RicoSuter / NSwag

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

Default Runtime causes code gen to fail when runtime is not specified in the document #3609

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi! Using

<Message Importance="High" Text="$(NSwagExe_Net50) aspnetcore2openapi /assembly:$(TargetDir)$(ProjectName).dll /output:swagger.json /runtime:net50" />

<Exec EnvironmentVariables="ASPNETCORE_ENVIRONMENT=$(Configuration)" Command="$(NSwagExe_Net50) aspnetcore2openapi /assembly:$(TargetDir)$(ProjectName).dll /output:swagger.json /runtime:net50" />

<Message Importance="High" Text="$(NSwagExe_Net50) run swagger.json /variables:Configuration=$(Configuration)" />

<Exec WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=$(Configuration)" Command="$(NSwagExe_Net50) run swagger.json /variables:Configuration=$(Configuration)" />

results in

dotnet "C:\Users\admin.nuget\packages\nswag.msbuild\13.13.2\build../tools/Net50/dotnet-nswag.dll" aspnetcore2openapi /assembly:D:\Project\bin\Debug\net5.0\Project.dll /output:swagger.json NSwag command line tool for .NET Core Net50, toolchain v13.13.2.0 (NJsonSchema v10.5.2.0 (Newtonsoft.Json v12.0.0.0)) Visit http://NSwag.org for more information. NSwag bin directory: C:\Users\admin.nuget\packages\nswag.msbuild\13.13.2\tools\Net50 Code has been successfully generated but not written to file (no change detected).

Duration: 00:00:01.9119636 dotnet "C:\Users\admin.nuget\packages\nswag.msbuild\13.13.2\build../tools/Net50/dotnet-nswag.dll" run swagger.json /variables:Configuration=Debug NSwag command line tool for .NET Core Net50, toolchain v13.13.2.0 (NJsonSchema v10.5.2.0 (Newtonsoft.Json v12.0.0.0)) Visit http://NSwag.org for more information. NSwag bin directory: C:\Users\admin.nuget\packages\nswag.msbuild\13.13.2\tools\Net50

Executing file 'swagger.json' with variables 'Configuration=Debug'... System.InvalidOperationException: The specified runtime in the document (NetCore21) differs from the current process runtime (Net50). Change the runtime with the '/runtime:NetCore21' parameter or run the file with the correct command line binary. at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in C:\projects\nswag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommand.cs:line 68 at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommand.cs:line 32 at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input) at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input) at NConsole.CommandLineProcessor.Process(String[] args, Object input) at NSwag.Commands.NSwagCommandProcessor.Process(String[] args) in C:\projects\nswag\src\NSwag.Commands\NSwagCommandProcessor.cs:line 55 D:\Project\Project.csproj(60,5): error MSB3073: The command "dotnet "C:\Users\admin.nuget\packages\nswag.msbuild\13.13.2\build../tools/Net50/dotnet-nswag.dll" run swagger.json /variables:Configuration=Debug" exited with code -1.

After 2hrs i found NSwagDocumentBase that default's Runtime property to Runtime.NetCore21.

Had to manually add a non-existent property runtime to my auto-generated swagger.json and comment the file generation task to get it to work.

Edit: formatting.

leonandroid commented 11 months ago

Does anybody knows the solution for this? He explains added a missing property with absolutely zero details how to solve it.