NSwag.MSBuild from Visual Studio 2017 .NET Core project

Created on 5 Mar 2017  路  5Comments  路  Source: RicoSuter/NSwag

I've tried adding the following to my .csproj file from a .NET Core project in Visual Studio 2017:

<Target Name="GenerateSwagger" AfterTargets="Build"> <Exec Command="$(NSwagExe) webapi2swagger /assembly:$(OutDir)\$(AssemblyName).dll /output:testswagger.json" /> </Target>

When I run the build, I get this:

System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Authentication, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.

It seems the tool doesn't know where to find the DLLs for referenced NuGet packages. Am I missing some config?

question

Most helpful comment

For others with a similar issue, my solution in asp.net core with a netcoreapp1.1 target was the following

  <Target Name="GenerateSwagger" AfterTargets="Build">
    <Exec Command="$(NSwagExe) webapi2swagger /assembly:$(OutDir)\$(AssemblyName).dll /ReferencePaths:%UserProfile%\.nuget\packages /output:$(OutDir)\storage.swagger.generated.json" />
  </Target>

I've added the nuget chache folder to ReferencePaths

All 5 comments

Run "dotnet publish" so that all required dlls are in the output dir

Thank you. That helped. I'm now getting

Could not load file or assembly 'System.Security.Claims, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I've added $(PublishOutput)\refs to the /referencePaths option, so it's looking where System.Security.Claims is, but my project actually references version 4.3.0 of that assembly - which is what's in that directory - so not sure why it's looking for 4.0.1.0. I'll close this for now while I try to figure out the versioning problem.

For others with a similar issue, my solution in asp.net core with a netcoreapp1.1 target was the following

  <Target Name="GenerateSwagger" AfterTargets="Build">
    <Exec Command="$(NSwagExe) webapi2swagger /assembly:$(OutDir)\$(AssemblyName).dll /ReferencePaths:%UserProfile%\.nuget\packages /output:$(OutDir)\storage.swagger.generated.json" />
  </Target>

I've added the nuget chache folder to ReferencePaths

@RSuter dotnet publish didn't work for me with an .net core app 2,

dotnet publish "C:\Folder\Mysolution.sln" --configuration Release
NSwag.exe webapi2swagger /assembly:"C:\Folder\bin\Release\netcoreapp2.0\publish\Mysolution.dll" /output:swagger.json

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.

@bqstony what path do you use in your build server?

Use the correct runtime:
https://github.com/RSuter/NSwag/wiki/MSBuild

Eg NSwagExe_Core11

Was this page helpful?
0 / 5 - 0 ratings