RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.78k stars 1.29k forks source link

The specified runtime in the document (Net70) differs from the current process runtime #4255

Closed madnik7 closed 1 year ago

madnik7 commented 1 year ago

The specified runtime in the document (Net70) differs from the current process runtime (WinX64). Change the runtime with the '/runtime:Net70' parameter or run the file with the correct command line binary.

I set the document runtime to Net70 and add /runtime:Net70 but I got the error. It works if I set both to Net60 nswag run "./Api/Api.nswag" /runtime:Net70

image

NSwag command line tool for .NET 4.6.1+ WinX64, toolchain v13.18.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))

davidkeaveny commented 1 year ago

I have a similar issue when running the NSwag.ConsoleCore CLI:

nswag.exe run open-api.nswag
NSwag command line tool for .NET Core Net70, toolchain v13.18.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: C:\Users\david.keaveny\.dotnet\tools\.store\nswag.consolecore\13.18.0\nswag.consolecore\13.18.0\tools\net7.0\any

Executing file 'D:\Bit\MyApi\open-api.nswag' with variables ''...
System.InvalidOperationException: The specified runtime in the document (Net60) differs from the current process runtime (Net70). Change the runtime with the '/runtime:Net60' parameter or run the file with the correct command line binary.
   at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 68
   at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 48
   at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
   at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 61

In this case, my application is compiled against .NET 6.0 (since it's an LTS release) rather than the newer-but-won't-be-supported-as-long .NET 7.0.

My open-api.nswag file starts off as:

{
  "runtime": "Net60",
  "defaultVariables": null,
  "documentGenerator": {
    "aspNetCoreToOpenApi": {
      "project": "MyApi.csproj",
      "msBuildProjectExtensionsPath": null,
      "configuration": "Release",
      "runtime": "Net60",

so as far as I can tell I'm setting runtime correctly. If I try calling nswag.exe with /runtime:Net60 I get exactly the same error.

mgreuelrwe commented 1 year ago

I have the same issue as @madnik7 It just seems to be the CLI installed with nswagStudio, via the npm tool it works just fine.

Maybe 70 is just missing in the cmd

RicoSuter commented 1 year ago

I have the same issue as @madnik7 It just seems to be the CLI installed with nswagStudio, via the npm tool it works just fine.

Maybe 70 is just missing in the cmd

Yeah that could be...

RicoSuter commented 1 year ago

Can you maybe patch the nswag.cmd in your install location to check whether this fixes it or more is needed?

mgreuelrwe commented 1 year ago

Can you maybe patch the nswag.cmd in your install location to check whether this fixes it or more is needed?

That does the trick!

RicoSuter commented 1 year ago

Oukey.. ill release a new version of nswag with the patch today...

mgreuelrwe commented 1 year ago

Perfect, thanks for the quick fix!

RicoSuter commented 1 year ago

v13.18.1

qwertie commented 1 year ago

I had this error in my csproj file and "fixed" it by replacing $(NSwagExe) with $(NSwagDir_Net70)dotnet-nswag:

  <!-- Before -->
  <Target Name="NSwag" AfterTargets="Build">
    <Exec Command="$(NSwagExe) run nswag.json /runtime:Net70 /variables:Configuration=$(Configuration)" />
  </Target>

  <!-- After -->
  <Target Name="NSwag" AfterTargets="Build">
    <Exec Command="$(NSwagDir_Net70)dotnet-nswag run nswag.json /runtime:Net70 /variables:Configuration=$(Configuration)" />
  </Target>

(it's not really fixed, as issue #4404 appeared right afterward.)

visschersm commented 4 days ago

When I am using a target file like nswag run somefolder\somespec.yml /runtime:net80 it gives the following error:

NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:net80]
   at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
   at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 65

When running the command nswag run /runtime:net80 from inside the folder with the api spec it does work. Is there a way around this issue?