Search code examples
c#.netnswag

NSWAG update to .NET6 - .NETPlatform,Version=v6.0 not found


I've updated all projects in my solution to use .net6, and have updated nswag json file to runtime to Net60.

I have .net 6.0.100 installed.

Here is the build output

$ dotnet build Solution.sln
Microsoft (R) Build Engine ersion 17.0.0+c9eb9dd64 for .NET

Restored C:\src\...\Client.csproj (in 455 ms).

NSwag command line tool for .NET Core Net60, toolchain v13.15.10.0 (NJsonSchema v10.6.10.0 (Newtonsoft.Json v13.0.0.0))

NSwag bin directory: C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\tools\Net60

Executing file 'nswag.json' with variables 'Configuration=Debug'...

C:\Program Files\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(1217,5): error MSB3644: The reference assemblies for .NETPlatform,Version=v6.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\src\API.csproj] [C:\src\...\.Client.csproj]

System.InvalidOperationException: Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project.If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
at NSwag.Commands.Generation.AspNetCore.ProjectMetadata.GetProjectMetadata(String file, String buildExtensionsDir, String framework, String configuration, String runtime, Boolean noBuild, String outputPath, IConsoleHost console) in /_/src/NSwag.Commands/Commands/Generation/AspNetCore/ProjectMetadata.cs:line 152

C:\src\....Client.csproj(15,5): error MSB3073: The command "dotnet "C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.

C:\Program Files\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(1217,5): error MSB3644: The reference assemblies for .NETPlatform,Version=v6.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\src\API.csproj] [C:\src\...\Client.csproj]

C:\src\...\.Client.csproj(15,5): error MSB3073: The command "dotnet "C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.

Solution

  • I did find a workaround - it gets me past the problem.

    In the nswag.json file, it fails when I reference the project in the project element of

    "documentGenerator": { 
      "aspNetCoreToOpenApi": {
        "project" "../relative/path/to/.csproj",
        "assemblyPaths": [
          "../../bin/dotnet6.0/MyAPI.dll"
        ]
       }
     }
    

    So remove project.

    And reference the output DLL from your project in the assemblyPaths[] array.

    It builds successfully & the client is regenerated.