RicoSuter / NSwag

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

'nswag run' reports InvalidOperationException: Unsupported target framework '.NETFramework' #2533

Closed qualitas-software closed 4 years ago

qualitas-software commented 4 years ago

I am trying to generate an OpenApi document for an ASP.NET Core 2.2 WebAPI that is set for target framework=net472, as part of MSBuild.

My .csproj file has the following relevant items, gleaned from the wikis : <TargetFramework>net472</TargetFramework> <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" /> <PackageReference Include="NSwag.MSBuild" Version="13.1.5">... <Target Name="NSwag" AfterTargets="Build">...

When I do a build I get the following error/info reported in the Build window:

21>NSwag command line tool for .NET Core NetCore22, toolchain v13.1.5.0 (NJsonSchema v10.0.27.0 (Newtonsoft.Json v11.0.0.0))
21>Visit http://NSwag.org for more information.
21>NSwag bin directory: C:\Users\peter1657\.nuget\packages\nswag.msbuild\13.1.5\tools\NetCore22
21>
21>Executing file 'nswag.json' with variables 'Configuration=Debug,OutDir=bin\Debug\net472\'...
21>System.InvalidOperationException: Unsupported target framework '.NETFramework'.
21>   at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiCommand.cs:line 89
21>   at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in C:\projects\nswag\src\NSwag.Commands\NSwagDocumentBase.cs:line 279
21>   at NSwag.Commands.NSwagDocument.ExecuteAsync() in C:\projects\nswag\src\NSwag.Commands\NSwagDocument.cs:line 81

Additionally the nswag.json looks like this (top part only):

{
  "runtime": "NetCore22",
  "documentGenerator": {
    "aspNetCoreToOpenApi": {
      "project": "MyProject.csproj",
      "msBuildProjectExtensionsPath": null,
      "configuration": "$(Configuration)",
      "runtime": null,
      "targetFramework": "net472",
      "noBuild": true,
      "verbose": true,
      "workingDirectory": null,

Any ideas what I need to adjust to make this work ?

qualitas-software commented 4 years ago

For anyone else who ends up here who is also using .NET Framework (4.7.2) & ASP.NET Core (2.2)...

I resolved this by making two changes:

In the .csproj file I changed: <Exec Command="$(NSwagExe_Core22) run ... " > to <Exec Command="$(NSwagExe) run ... " >

And in the nswag.json, I change the runtime property to "WinX64"