【问题标题】:Different client output when used Autorest.exe vs ADD->Rest API Client使用 Autorest.exe 与 ADD->Rest API 客户端时不同的客户端输出
【发布时间】:2017-05-07 07:50:58
【问题描述】:

我正在尝试使用 Swagger 为 WebAPI 生成客户端代码。我通常通过下载元数据 json 文件(在部署 WebAPI 之后)然后为客户端类库使用选项“Add->Rest API Client..”来做到这一点。

Add -> Rest API Client

这将为所需的项目生成客户端库并且工作正常。但我正在尝试使用 Autorest.exe 自动化这个过程。我写了小代码来执行 Autorest.exeparameters 生成客户端代码如下

string filename = @"C:\Users\xxxx\packages\AutoRest.0.9.7\tools\AutoRest.exe";
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = filename;
startInfo.Arguments = "-CodeGenerator CSharp -Modeler CompositeSwagger -Input http://WebAPIDomainNameGoesHere:80/swagger/docs/v1 -Namespace CESOutboundAPI.ClientLibrary";
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();

但是新生成的客户端代码不起作用(无法构建),并且与我在 Visual Studio 中使用 GUI 选项时得到的输出不相似。

当我尝试构建新生成的代码时,我收到每个 .cs 文件的以下错误消息。

The type or namespace name 'ValidationRules' does not exist in the namespace 'Microsoft.Rest' (are you missing an assembly reference?)  
The type or namespace name 'SerializationException' does not exist in the namespace 'Microsoft.Rest' (are you missing an assembly reference?)   
The type or namespace name 'Serialization' does not exist in the namespace 'Microsoft.Rest' (are you missing an assembly reference?)    
The type or namespace name 'HttpResponseMessageWrapper' does not exist in the namespace 'Microsoft.Rest' (are you missing an assembly reference?)   
.
.

我需要帮助自动生成可以完美执行并与 GUI 生成的内容相匹配的客户端代码。提前致谢。

【问题讨论】:

    标签: c# swagger swashbuckle azure-api-apps autorest


    【解决方案1】:

    确实,VS 中的 AutoRest 版本已经很老了,你真的不想使用它。

    获取最新版本的 AutoRest(安装到 c:\autorest ... 更改为您喜欢的任何位置。)

    确保您拥有 NuGet 3.4 或更高版本。

    最新的夜间版本

    NuGet.exe install AutoRest -source https://www.myget.org/F/autorest/api/v3/index.json -prerelease -outputdirectory c:\autorest 
    

    最新的稳定版本

    NuGet.exe install AutoRest -outputdirectory c:\autorest 
    

    【讨论】:

      【解决方案2】:

      我终于弄清楚了这个问题。我正在使用不同版本的 Autorest.exe 来生成我的客户端,而 Visual Studio“添加 - > Rest API 客户端”正在使用另一个版本。在我下载所需的版本并使用上面相同的命令后,它就像魅力一样。

      【讨论】:

        猜你喜欢
        • 2020-02-15
        • 1970-01-01
        • 2016-09-28
        • 2013-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-11
        相关资源
        最近更新 更多