Nswag: .NET 5 NSwagExe MSBuild Property

Created on 27 Aug 2020  Â·  19Comments  Â·  Source: RicoSuter/NSwag

We're working on preparing our codebase for .NET 5 release in November. Is there a planned naming convention for NSwagExe MSBuild properties following .NET 5 removing "Core"/"Framework"? Maybe NSwagExe_Net5?

enhancement

Most helpful comment

NSwag v13.9.0 released with .NET 5.0 support - please test and report any problems.

All 19 comments

Didnt think about this yet, but NSwagExe_Net5 make sense.

Now that that the release candidate is out, is there any news on support for .NET 5?

Can't you reference and use the current version of NSwag.AspNetCore?

I'm using NSwag.MSBuild to generate a client for my API and it's giving me

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

when i try and build.

Can't you reference and use the current version of NSwag.AspNetCore?

OpenAPI generation works just fine in .NET 5 build, VS 2019 preview using NSwagExe_Core31. Using just-released VS preview and nightly build of dotnet SDK, RC2 preview.

Is that different from RC1? What command are you using to make that work?

I would expect that NSwag.AspNetCore still works as it is “hosted” by a .net 5 process, however NSwag.MSBuild might fail because it’s a .net core 3.1 process loading .net 5 dlls/projects

It's different from RC1 in the sense that it's a RC2 nightly build. I would not expect any of those differences to be relevant to NSwag behavior.

<Target Name="GenerateSwaggerDoc" AfterTargets="Build" Condition=" '$(RuntimeIdentifier)' != 'linux-arm64' ">
  <Copy SourceFiles="@(Reference)" DestinationFolder="$(OutDir)References" />
  <Exec Command="$(NSwagExe_Core31) run nswag.json /variables:Configuration=$(Configuration)" />
</Target>

Yeah -- that is an interesting point. Depending on the assemblies being loaded and their target arch you could run into something funny.

I would expect that NSwag.AspNetCore still works as it is “hosted” by a .net 5 process

Of course only if they didnt break an api which nswag relies on (eg api explorer). Maybe there is also more metadata we can/should support. But for that we’d need to check the changes

not sure when we can expect the new NSwagExe_Net5, any update?

Any idea when the .NET 5 support will be given? Can we support it?... Would like to create a PR for that issue

@RicoSuter Please have a look at the PR. This is imho important as many projects using NSwag want to make the change to .NET 5. Thank you in advance.

Updating to the newest version of Visual Studio breaks existing projects that use $(NSwagExe_Core31) even if you never changed your target framework:

.csproj

  <Target Name="NSwag" BeforeTargets="PrepareForBuild" Condition="'$(GenerateCode)'=='True' And '$(Configuration)'!='Release' ">
    <Exec Command="$(NSwagExe_Core31) run nswag.json /variables:Configuration=$(Configuration)" />
  </Target>

build output

error MSB3073: The command " run nswag.json /variables:Configuration=Debug" exited with code 9009

Edit:

Workaround by explicitly specifying an sdk in a global.json file:

{
  "sdk": {
    "version": "3.1"
  }
}

Why is that? Because its built by net 50 or because you just installed net 50?

It seems the newest version of Visual Studio (16.8.0) includes .NET 5.0 SDK and defaults to it even if you are using a netcoreapp3.1 project. I did not install .NET 5 manually. However, I noticed if I try to build the project using using the CLI (dotnet build) it seems to work fine.

@phil-harmoniq VS default behavior is to use the latest SDK available on the system & VS 16.8 to the best of my knowledge cannot be installed without .NET 5 so makes sense. You can override the SDK used by VS — don’t recall off hand how, but should be easily googled.

NSwag v13.9.0 released with .NET 5.0 support - please test and report any problems.

Seems to be working fine. Managed to build in VS 16.8.1, in console using dotnet build -f net5.0 and also in docker image mcr.microsoft.com/dotnet/sdk:5.0

Pasting this for reference, the dll name was giving me a hard time: NSwagExe_Net50 vs NSwagExe_Net5 mentioned above.

<Target Name="NSwag" AfterTargets="Build">
    <Copy SourceFiles="@(Reference)" DestinationFolder="$(OutDir)References" />
    <Exec Command="$(NSwagExe_Net50) run nswag.json /variables:Configuration=$(Configuration) /runtime:Net50" />
    <RemoveDir Directories="$(OutDir)References" />
  </Target>

Thanks guys for a quick upgrade.

Was this page helpful?
0 / 5 - 0 ratings