2016-12-21 8 views
1

Swagger로 WebAPI 용 클라이언트 코드를 생성하려고합니다. 필자는 보통 WebAPI를 배포 한 후 메타 데이터 json 파일을 다운로드 한 다음 클라이언트 클래스 라이브러리에 대해 "Add-> Rest API Client .."옵션을 사용하여이 작업을 수행합니다.사용할 때 다른 클라이언트 출력 Autorest.exe 대 ADD-> 나머지 API 클라이언트

Add -> Rest API Client.

이렇게하면 원하는 프로젝트에 클라이언트 라이브러리가 생성되어 정상적으로 작동합니다. 하지만 Autorest.exe를 사용하여이 프로세스를 자동화하려고합니다. 나는

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(); 

아래와 같이 클라이언트 코드 그러나 (빌드되지 않음)이 작동하지 않습니다 새로 생성 된 클라이언트 코드를 생성 할 parameters에게 Autorest.exe을 실행하는 작은 코드를 작성하고 유사하지 무엇 나는 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가 생성하는 것과 일치하는 클라이언트 코드 생성을 자동화하는 데 도움이 필요합니다. 미리 감사드립니다.

답변

0

마침내 문제가 발생했습니다. 다른 버전의 Autorest.exe를 사용하여 Visual Studio "추가 -> 나머지 API 클라이언트"가 다른 버전을 사용하고있는 클라이언트를 생성했습니다. 위와 같은 명령을 사용하여 필요한 버전을 다운로드 한 후에는 매력과 같이 작동했습니다.

2

실제로 VS에 포함 된 AutoRest의 버전은 꽤 오래된 버전이며 실제로 사용하고 싶지 않습니다.

은 (당신이 그것을 원하는 위치로 변경 ... c:\autorest로 설치합니다.) 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