使用以下命令行中的文章Generating API clients using AutoRest中的示例MS PowerShell脚本时,出现主题错误消息
dotnet swagger "tofile" --output "../../res/swagger.json" "../Sample.Api/bin/Debug/netcoreapp2.1/Sample.Api.dll" v1
被执行。解决方案?
仅供参考:Swashbuckle.AspNetCore.Cli条目源代码位于此处:Swashbuckle.AspNetCore/src/Swashbuckle.AspNetCore.Cli/Program.cs
更新
我应该发布运行时错误消息的全文-这是
At C:\Tests\Swashbuckle\build.ps1:8 char:1
+ dotnet swagger "tofile" --output "../../res/swagger.json" "../Sample. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.OpenApi,
Version=1.1.1.0, Culture=neutral, PublicKeyToken=3f5743946376f042'.
The system cannot find the file specified.
at Swashbuckle.AspNetCore.Cli.Program.<>c.<Main>b__0_3(IDictionary`2 namedArgs)
at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args)
at Swashbuckle.AspNetCore.Cli.CommandRunner.Run(IEnumerable`1 args)
at Swashbuckle.AspNetCore.Cli.Program.Main(String[] args)
答案 0 :(得分:1)
通过引用Swashbuckle.AspNetCore和Swashbuckle.AspNetCore.Annotations软件包以及Swashbuckle.AspNetCore.Cli工具的v.4.0.1(或v.5.0.0-beta)解决了该问题:
...
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Swashbuckle.AspNetCore.Cli" Version="4.0.1" />
</ItemGroup>
答案 1 :(得分:1)
我使用以下方法摆脱了这个问题。
将大刀阔斧升级到5.0.0-rc3,我的csproj看起来像这样
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc3" />
</ItemGroup>
然后我使用以下代码安装了swagger cli,因为您必须已经安装
dotnet tool install -g swashbuckle.aspnetcore.cli --version 5.0.0-rc3
最后运行命令
swagger "tofile" --output "../../res/swagger.json" "../Sample.Api/bin/Debug/netcoreapp2.1/Sample.Api.dll" v1
确保在运行上述命令后在路径中摇摇晃晃。