NSwag build error — Project file does not exist / Unable to retrieve project metadata

Alex Brown
1 min readNov 26, 2019

While working on a project that used NSwag, when the solution was built, Visual Studio (and dotnet build from the command line) reported the following error

Pretty frustrating, as it wasn’t clear what the error meant.
This project used NSwag.MSBuild to generate the client on build.

As per their documentation, we had an after build target:

<Exec Command=”$(NSwagExe_Core22) aspnetcore2openapi /project:$(ProjectDir)\..\$(ApiProjName)\$(ApiProjName).csproj /output:swagger.json “ />

The problem here was that it wasn’t taking in to account that my directory had a space in it:
C:\Users\Alex Brown\my-project

Changing the target to add quotes around the path fixed the issue:
This is done by using &quot; as seen below:

<Exec Command=”$(NSwagExe_Core22) aspnetcore2openapi /project:&quot;$(ProjectDir)/../$(ApiProjName)/$(ApiProjName).csproj&quot; /output:swagger.json -no-build” />

--

--