3

当使用以下命令行时,我在使用文章使用 AutoRest 生成 API 客户端中的示例 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)
4

2 回答 2

2

我已经使用以下方法来解决这个问题。

swagger升级到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

确保在运行上述命令后您的路径中充满自信。

于 2019-11-17T08:36:26.653 回答
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>
于 2018-12-29T10:40:48.907 回答