NSWAG 更新到 .NET6 - .NETPlatform,Version=v6.0 not found
NSWAG update to .NET6 - .NETPlatform,Version=v6.0 not found
我已将解决方案中的所有项目更新为使用 .net6,并将 nswag json 文件更新为 runtime
到 Net60。
我安装了 .net 6.0.100。
这是构建输出
$ 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.15.10\tools\Net60
Executing file 'nswag.json' with variables 'Configuration=Debug'...
C:\Program Files\dotnet\sdk.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.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.
C:\Program Files\dotnet\sdk.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.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.
我确实找到了解决方法 - 它让我解决了这个问题。
在nswag.json
文件中,当我在
的project
元素中引用项目时失败
"documentGenerator": {
"aspNetCoreToOpenApi": {
"project" "../relative/path/to/.csproj",
"assemblyPaths": [
"../../bin/dotnet6.0/MyAPI.dll"
]
}
}
所以去掉project
.
并在 assemblyPaths[]
数组中引用您项目的输出 DLL。
构建成功,重新生成客户端。
我已将解决方案中的所有项目更新为使用 .net6,并将 nswag json 文件更新为 runtime
到 Net60。
我安装了 .net 6.0.100。
这是构建输出
$ 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.15.10\tools\Net60
Executing file 'nswag.json' with variables 'Configuration=Debug'...
C:\Program Files\dotnet\sdk.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.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.
C:\Program Files\dotnet\sdk.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.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.
我确实找到了解决方法 - 它让我解决了这个问题。
在nswag.json
文件中,当我在
project
元素中引用项目时失败
"documentGenerator": {
"aspNetCoreToOpenApi": {
"project" "../relative/path/to/.csproj",
"assemblyPaths": [
"../../bin/dotnet6.0/MyAPI.dll"
]
}
}
所以去掉project
.
并在 assemblyPaths[]
数组中引用您项目的输出 DLL。
构建成功,重新生成客户端。