我在 Swashbuckle.AspNetCore 版本 5.0.0-rc2 上遇到问题,如这篇文章“https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1185”中所述。
所以我添加了版本 5.0.0-rc3 的每日构建,当前版本为 5.0.0-rc3-preview-0941,来自“https://www.myget.org/feed/domaindrivendev/package/nuget/Swashbuckle.AspNetCore”。我通过将 myget 源添加到 VS2019 来做到这一点。
添加 rc3 后,出现以下构建错误。我不确定这是 Swashbuckle 的问题还是其他问题。
Severity Code Description Project File Line Suppression State
Error MSB3073 The command "dotnet "C:\Users\CTGCntrols\.nuget\packages\microsoft.extensions.apidescription.server\0.3.0-preview7.19365.7\build\/../tools/dotnet-getdocument.dll" --assembly "C:\Users\CTGCntrols\Source\Repos\FlameMetals\API\bin\Debug\netcoreapp3.0\API.dll" --file-list "obj\API.OpenApiFiles.cache" --framework ".NETCoreApp,Version=v3.0" --output "obj" --project "API" --assets-file "C:\Users\CTGCntrols\Source\Repos\FlameMetals\API\obj\project.assets.json" --platform "x64" " exited with code 7. API C:\Users\CTGCntrols\.nuget\packages\microsoft.extensions.apidescription.server\0.3.0-preview7.19365.7\build\Microsoft.Extensions.ApiDescription.Server.targets 41
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc3-preview-0931" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0-rc2" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.0.0-rc8" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.0.0-rc3-preview-0931" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.0.0-rc3-preview-0931" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc3-preview-0931" />
最佳答案
实际的异常被吞没了。文档生成失败,因为:
System.NotSupportedException: Ambiguous HTTP method for action - XXX.Controllers.ControllerYYY.ActionZZZ. Actions require an explicit HttpMethod binding for Swagger 2.0
这是一个纯粹与 swagger 相关的错误。我之前在 Visual Studio 2017 的 Error List
窗口中看到了该错误,但我猜他们仍在准备 VS 2019 和 .NET Core...
您可以通过手动执行上述命令来查看实际异常。只需打开命令提示符窗口并粘贴文本:
dotnet "C:\Users\CTGCntrols.nuget\packages\microsoft.extensions.apidescription.server\0.3.0-preview7.19365.7\build/../tools/dotnet-getdocument.dll"--程序集 "C:\Users\CTGCntrols\Source\Repos\FlameMetals\API\bin\Debug\netcoreapp3.0\API.dll"--file-list "obj\API.OpenApiFiles.cache"--framework ".NETCoreApp, Version=v3.0"--output "obj"--project "API"--assets-file "C:\Users\CTGCntrols\Source\Repos\FlameMetals\API\obj\project.assets.json"--platform “x64”
更新
实际上,XML 文档生成过程中的任何异常都可能导致构建错误。例如,如果路由路径中有拼写错误并且路由模板无效,您将得到相同的构建错误。
所描述的行为是在 .NET Core 3.0 和 Visual Studio 2019 PREVIEW 版本 .16.4.0 中遇到的。预览版 1.0
关于visual-studio-2019 - 当我执行 "dotnet run"时出现构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57549082/