RicoSuter / NSwag

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

Nswag 14 CLI /runtime argument not running with Net80 #4678

Open dylanvdmerwe opened 11 months ago

dylanvdmerwe commented 11 months ago

Runtime specified in nswag.json as "Net80".

image

Not quite sure if it's needed in both places, but did it to make sure.

Then run the Nswag CLI tool (npm i -g nswag@14) run command:

> nswag run ..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json

NSwag NPM CLI
NSwag command line tool for .NET Core Net70, toolchain v14.0.0.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: C:\Users\Dylan\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin\binaries\Net80

Executing file '..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json' with variables ''...
System.InvalidOperationException: The specified runtime in the document (Net80) differs from the current process runtime (Net70). Change the runtime with the '/runtime:Net80' 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 69
   at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 33
   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 62node:child_process:965
    throw err;
    ^

Error: Command failed: dotnet "C:\Users\Dylan\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin/binaries/Net80/dotnet-nswag.dll" run ..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json
    at checkExecSyncError (node:child_process:890:11)
    at Object.execSync (node:child_process:962:15)
    at C:\Users\DylanvanderMerwe\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin\nswag.js:64:27
    at ChildProcess.exithandler (node:child_process:414:7)
    at ChildProcess.emit (node:events:517:28)
    at maybeClose (node:internal/child_process:1098:16)
    at ChildProcess._handle.onexit (node:internal/child_process:303:5) {
  status: 4294967295,
  signal: null,
  output: [ null, null, null ],
  pid: 73448,
  stdout: null,
  stderr: null
}

Alright then let's set the /runtime parameter with the CLI:

> nswag run ..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json /runtime:Net80

NSwag NPM CLI
NSwag command line tool for .NET Core Net70, toolchain v14.0.0.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: C:\Users\Dylan\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin\binaries\Net80
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 62node:child_process:965
    throw err;
    ^

Error: Command failed: dotnet "C:\Users\Dylan\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin/binaries/Net80/dotnet-nswag.dll" run ..\..\..\WebServiceProjects\WebService.PortalApi\nswag.json /runtime:Net80
    at checkExecSyncError (node:child_process:890:11)
    at Object.execSync (node:child_process:962:15)
    at C:\Users\DylanvanderMerwe\AppData\Roaming\nvm\v18.18.0\node_modules\nswag\bin\nswag.js:57:19
    at ChildProcess.exithandler (node:child_process:414:7)
    at ChildProcess.emit (node:events:517:28)
    at maybeClose (node:internal/child_process:1098:16)
    at ChildProcess._handle.onexit (node:internal/child_process:303:5) {
  status: 4294967295,
  signal: null,
  output: [ null, null, null ],
  pid: 32788,
  stdout: null,
  stderr: null
}

The correct runtime is specified in the config file.

It seems like there is an issue with the CLI. Please advise how to get this working as after updating to net80 we cannot use nswag via the CLI to generate Typescript.

krzyhan commented 11 months ago

As mentioned in log, cmd is using Net70 instead of Net80 I think, #4680 should resolve this issue

dylanvdmerwe commented 11 months ago

@krzyhan Yes that looks to be the issue. Well found, I was hunting but came up with nothing.

Let's hope this can get published soonest.

ptasev commented 10 months ago

I'm still getting this issue with 14.0.1 when calling openapi2tsclient /runtime:Net80 /input:....OpenAPI.json

NSwag command line tool for .NET Core Net80, toolchain v14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
NSwag bin directory: /blabla/node_modules/nswag/bin/binaries/Net80
NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net80]
jeldert commented 10 months ago

@ptasev I have the same error. After i removed /runtime:Net80 the command completes succesfully! This did not work in 14.0.0, but seems to fix it in 14.0.1

tomvdk commented 10 months ago

Same here but had to remove the /runtime:Net60 argument in the nswag command nswag run client.nswag using version 14.0.1

Seems like the runtime argument in the cli is not used anymore?


NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net60]
ptasev commented 10 months ago

I'm really confused if we really are no longer supposed to be using this, or if it's a bug. I see there's runtime here but it's defaulted to Net60: https://github.com/RicoSuter/NSwag/blob/313ea53f4f8a53c0e66b0f84f63f3224bfcebcac/src/NSwag.Commands/NSwagDocumentBase.cs#L60

Also, nswag npm.js seems to accept the runtime argument, considering that it converts legacy args to using runtime, so I'm not sure what to think: https://github.com/RicoSuter/NSwag/blob/313ea53f4f8a53c0e66b0f84f63f3224bfcebcac/src/NSwag.Npm/bin/nswag.js#L17

MehdiElMellali commented 10 months ago

nswag run /runtime:Net80

 Ensure that the project has been built.
   at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs:line 82
   at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in /_/src/NSwag.Commands/NSwagDocumentBase.cs:line 270
   at NSwag.Commands.NSwagDocument.ExecuteAsync() in /_/src/NSwag.Commands/NSwagDocument.cs:line 67
   at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 76
   at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 40
   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 62

any idea about this error please!

krzyhan commented 10 months ago

I'm still getting this issue with 14.0.1 when calling openapi2tsclient /runtime:Net80 /input:....OpenAPI.json

NSwag command line tool for .NET Core Net80, toolchain v14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
NSwag bin directory: /blabla/node_modules/nswag/bin/binaries/Net80
NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net80]

remove /runtime:Net80

Same here but had to remove the /runtime:Net60 argument in the nswag command nswag run client.nswag using version 14.0.1

Seems like the runtime argument in the cli is not used anymore?

NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net60]

for run command runtime is supported but only for default config files (so it will take default nswag.json or *.nswag files)

krzyhan commented 10 months ago

nswag run /runtime:Net80

 Ensure that the project has been built.
   at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs:line 82
   at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in /_/src/NSwag.Commands/NSwagDocumentBase.cs:line 270
   at NSwag.Commands.NSwagDocument.ExecuteAsync() in /_/src/NSwag.Commands/NSwagDocument.cs:line 67
   at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 76
   at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 40
   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 62

any idea about this error please!

do you have documentGenerator.aspNetCoreToOpenApi.noBuild set to false?

seems like project has not been built yet

Tridus commented 4 months ago

Still an issue in 14.0.8. Running from the command line without /runtime:Net80 tells you to add it. Running with it tells you to remove it.

nswag run file.nswag.json

NSwag command line tool for .NET 4.6.2+ WinX64, toolchain v14.0.8.0 (NJsonSchema v11.0.1.0 (Newtonsoft.Json v13.0.0.0))

Visit http://nswag.org/ for more information.

NSwag bin directory: C:\Program Files (x86)\Rico Suter\NSwagStudio\Win

Executing file 'enviApi.nswag.json' with variables ''...

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

at NSwag.Commands.Document.ExecuteDocumentCommand.d__9.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at NSwag.Commands.Document.ExecuteDocumentCommand.d__8.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at NConsole.CommandLineProcessor.d__12.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at NConsole.CommandLineProcessor.d__11.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

at NSwag.Commands.NSwagCommandProcessor.d__3.MoveNext()

nswag run file.nswag.json /runtime:Net80

NSwag command line tool for .NET Core Net80, toolchain v14.0.8.0 (NJsonSchema v11.0.1.0 (Newtonsoft.Json v13.0.0.0))

Visit http://nswag.org/ for more information.

NSwag bin directory: C:\Program Files (x86)\Rico Suter\NSwagStudio\Net80

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

Renaming the file to file.nswag and then running this does work: nswag run /runtime:Net80

geminixandroid commented 4 months ago

Removing passed runtime argument in nswag.cmd works for me.

@ECHO OFF
set args=%*

IF NOT "%args:/runtime:winx86=%" == "%args%" (
    "%~dp0/Win/nswag.x86.exe" %*
    GOTO end
)

IF NOT "%args:/runtime:net60=%" == "%args%" (
    dotnet "%~dp0/Net60/dotnet-nswag.dll" %*
    GOTO end
)

IF NOT "%args:/runtime:net70=%" == "%args%" (
-   dotnet "%~dp0/Net70/dotnet-nswag.dll" %*
+   dotnet "%~dp0/Net70/dotnet-nswag.dll" %args:/runtime:net70=%
    GOTO end
)

IF NOT "%args:/runtime:net80=%" == "%args%" (
    dotnet "%~dp0/Net80/dotnet-nswag.dll" %*
    GOTO end
)

"%~dp0/Win/nswag.exe" %*
:end
kgopdev commented 3 months ago

Still an issue in 14.1 Running from the command line without /runtime:Net60 tells you to add it. Running with it tells you to remove it. Any suggestions as to how I can run it for a .NET 6.0 project.

With /runtime:Net60 NSwag NPM CLI NSwag command line tool for .NET Core Net60, toolchain v14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0)) Visit http://NSwag.org for more information. NSwag bin directory: C:\Git\custom-elements\node_modules\nswag\bin\binaries\Net60 NConsole.UnusedArgumentException: Unrecognised arguments are present: [/runtime:Net60] 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 65node:child_process:965 throw err; ^

Without /runtime:Net60 System.InvalidOperationException: The specified runtime in the document (Net60) differs from the current process runtime (Net80). 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 69 at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 33 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 65node:child_process:965

ptasev commented 3 months ago

I presume your nswag json file specifies the runtime as .NET 6 despite the assembly being .NET 8. You'll have to change the settings.

MrChriZ commented 1 month ago

Seeing the same here : System.InvalidOperationException: The specified runtime in the document (Net80) differs from the current process runtime (WinX64). Change the runtime with the '/runtime:Net80' parameter or run the file with the correct command line binary. at NSwag.Commands.Document.ExecuteDocumentCommand.d__9.MoveNext()

"runtime": "Net80" specified in the nswag file

MrChriZ commented 1 month ago

I agree with Tridus. Omitting the file name works. Definitely seems like a bug.