从 OpenAPI 规范生成客户端代码失败

Generating client code from OpenAPI spec fails

我偶然发现了 this article,出于好奇,我试了一下。我可以从我们的 ASP.NET Core Web API.

成功生成 OpenAPI 规范作为 JSON 文件

但是,当尝试在 Visual Studio 2019 年内创建 Connected Service 以根据 OpenAPI 规范生成客户端代码时,失败并显示以下内容错误:

NuGet.PackageManagement.PackageReferenceRollbackException: Package restore failed. 

任何想法可能是错误的?如何确定缺少哪个包裹?它与我的 OpenAPI 规范有关还是 Visual Studio 工作流程的问题?

您可以尝试清除 NuGet 缓存吗? VS 工具 > 选项 > Nuget 包管理器 > 常规 > 清除所有 Nuget 缓存。

我终于在添加Connected Service时发现如下错误信息:

Warning MSB3106 Assembly strong name "C:\Users\ME\.nuget\packages\newtonsoft.json.0.3\lib\netstandard2.0\Newtonsoft.Json.dll" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).

通过将以下行添加到我的项目文件中,错误消失了,我可以成功生成客户端代码:

<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />