Kirsten
Kirsten

Reputation: 18188

MSB3037 openapi2csclient exited with code -1

I used Visual Studio Add-Service-Reference to add a service that uses the OpenAPI Specification. Add service reference

I input the swagger URL and generated the code.

The .csproj indicates that the service is configured. service reference

However when I try to build I get an error.

The wizard contained this link

The service was generated using AutoRest. I am using VS2022 17.2.5

The full error is

Error MSB3073 The command ""C:\Users\kirst.nuget\packages\nswag.msbuild\13.0.5\build../tools/Win/NSwag.exe" openapi2csclient /className:myapicls /namespace:myapi /input:D:\dev\MyApi\UnitTestProject1\OpenAPIs\index.html /output:obj\indexClient.cs " exited with code -1. UnitTestProject1 C:\Users\kirst.nuget\packages\nswag.apidescription.client\13.0.5\build\NSwag.ApiDescription.Client.targets 28

Upvotes: 5

Views: 1912

Answers (2)

Jens Caasen
Jens Caasen

Reputation: 597

If anyone else ends up here but got the URL correct (usually its /api/swagger.json) there might be a problem with spaces in the path to the project. I started to have this problem after checking out a project to another machine.

The fix was in the file C:\Users\{user}\.nuget\packages\nswag.apidescription.client\13.0.5\build\NSwag.ApiDescription.Client.targets

in Line 21:

    <Command>%(Command) /input:%(FullPath) /output:%(OutputPath) %(Options)</Command>

To make swagger whitespace compatible, change that line to:

    <Command>%(Command) /input:"%(FullPath)" /output:"%(OutputPath)" %(Options)</Command>

Error is gone after that

Upvotes: 1

Helen
Helen

Reputation: 98011

A service reference expects an OpenAPI YAML/JSON document, not the Swagger UI web page. This answer explains how you can find the URL of your OpenAPI YAML/JSON file or export it from Swagger UI.

Upvotes: 2

Related Questions