I am trying to generate client code for WebAPI with Swagger. I usually do that by downloading the metadata json file (after deploying WebAPI) and then use the option "Add->Rest API Client.." for the client class library.
This will generate client library to the desired project and works fine. But i am trying to automate this process using Autorest.exe. I wrote small code to execute Autorest.exe with parameters to generate the client code as below
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();
But the newly generated client code doesn't work (doesn't build) and isn't similar to what i get as output when i use GUI options in visual studio.
When i try building the newly generated code, i get the following error messages for each .cs file.
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?)
.
.
I need help with automating generation of client code that executes perfectly and matches to what GUI generates. Thanks in advance.
I finally figured out the issue. I was using a different version of Autorest.exe to generate my client where as Visual Studio "Add -> Rest API Client" is using another version. After I downloaded the version needed and used the same command above, it worked like charm.