我想用Swagger爲WebAPI生成客戶端代碼。我通常通過下載元數據json文件(在部署WebAPI之後)來完成此操作,然後使用客戶端類庫的選項「Add-> Rest API Client ..」。使用Autorest.exe時不同的客戶端輸出與ADD-> Rest API客戶端
這將生成客戶端庫到所需的項目,並正常工作。但我正在嘗試使用Autorest.exe自動執行此過程。我寫了一小段代碼執行Autorest.exe與parameters生成客戶端代碼如下
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生成的內容匹配。提前致謝。