Swashbuckle.AspNetCore.Cli only targets .NET Core 2.1

Created on 20 Sep 2019  路  15Comments  路  Source: domaindrivendev/Swashbuckle.AspNetCore

Package: Swashbuckle.AspNetCore.Cli
Version: 5.0.0-rc3
Project Target Framework: netcoreapp3.0

Reproduction Steps:

  1. Create .NET Core 3.0 API project
  2. Configure Swashbuckle.AspNetCore-5.0.0-rc3
  3. Run dotnet tool run swagger tofile --output output/swagger.json bin/Release/netcoreapp3.0/MyWebApi.dll v1

Description:
I have a .NET Core 3.0 project that includes Swashbuckle.AspNetCore-5.0.0-rc3 that I am trying to use the CLI to build a swagger file for during the build process. I have tool included in my dotnet tools manifest and when I restore, it installs correctly. However when I run the command, I get the following. Since Swashbuckle.AspNetCore-5.0.0-rc3 supports netcoreapp3.0, I suspect the CLI should as well.

Tool 'swashbuckle.aspnetcore.cli' (version '5.0.0-rc3') was restored. Available commands: swagger

Restore was successful.
It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
  - The following frameworks were found:
      3.0.0-rc1-19456-20 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

Most helpful comment

Just discovered you can use the environment variable:

DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2 to work around this.

https://github.com/dotnet/core-setup/blob/master/Documentation/design-docs/multilevel-sharedfx-lookup.md

Looks like they there is a RollForward property for the csproj file. I tried adding it to my own project file, but it did not work, so I'm thinking it needs to go on the Swashbuckle CLI project file.

All 15 comments

Did you follow the installation guide here?

I just followed these steps on a fresh .NET Core 3.0 app and can confirm they worked without a problem.

With a netcoreapp2.2 targeted app I get the following error although it will still generate the file and builds successfully

NU1202  Package Swashbuckle.AspNetCore.Cli 5.0.0-rc3 is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2). Package Swashbuckle.AspNetCore.Cli 5.0.0-rc3 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1) / any

Ignore the above as I was only an error within Visual Studio and was due to me referencing the tool via the csproj

<ItemGroup>
    <DotNetCliToolReference Include="Swashbuckle.AspNetCore.Cli" Version="5.0.0-rc3" />
</ItemGroup>

vs installing the tool locally/globally via

dotnet tool install swashbuckle.aspnetcore.cli --version 5.0.0-rc3

@domaindrivendev It looks like this only works with .NET Core 3 if .NET Core 2.1 is installed also. Generating a swagger.json file works on my local machine as I have both SDKs installed but I am getting a similar error to @kluhman when I try to generate a swagger.json file with Docker. The issue here is that I can only have one .NET Core SDK in my Dockerfile which is .NET Core 3 so .NET 2.1 is missing. Or am I missing something?

@mister-conor, I installed .NET Core 2.1 SDK - Windows x64 Installer (v2.1.802), but I am still getting the error.

I'm hitting the same problem. Locally, I can run dotnet swagger or dotnet tool swagger and generate the swagger file, but when building in a Docker container from mcr.microsoft.com/dotnet/core/sdk:3.0, I get the following:

  The specified framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
    - The following frameworks were found:
        3.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

  You can resolve the problem by installing the specified framework and/or SDK.

I've made a reproduction repository here:

https://github.com/ericl85/SwaggerCliRepro

Here's my dotnet --info locally where it works:

.NET Core SDK (reflecting any global.json):                                                                              Version:   3.0.100                                                                                                      Commit:    04339c3a26                                                                                                                                                                                                                          Runtime Environment:                                                                                                     OS Name:     ubuntu                                                                                                     OS Version:  18.04                                                                                                      OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  95a0a61858

.NET Core SDKs installed:
  2.2.401 [/usr/share/dotnet/sdk]
  3.0.100 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Strangely enough, I don't even have 2.1.0 installed.

Just discovered you can use the environment variable:

DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2 to work around this.

https://github.com/dotnet/core-setup/blob/master/Documentation/design-docs/multilevel-sharedfx-lookup.md

Looks like they there is a RollForward property for the csproj file. I tried adding it to my own project file, but it did not work, so I'm thinking it needs to go on the Swashbuckle CLI project file.

@domaindrivendev Your guide says run "dotnet tool install swashbuckle.aspnetcore.cli --version 5.0.0-rc5". RC5 doesn't exist.

I'm getting the same error after upgrading from v5.1.0 to v5.4.1. The last version working for me is v5.3.3.

It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
  - The following frameworks were found:
      3.1.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

@aelij The CLI component needs to be installed as a .NET Tool as opposed to a project reference. If you follow the installation steps from the readme, it should work against an app targeting netcoreapp3.1 without issue. I've verified this myself locally. Please try that if you haven't done so already and let me know how it goes.

@domaindrivendev It was installed as a CLI tool and worked fine until I upgraded the version by editing the manifest file and restoring.

Have you tried this on a machine that doesn't have .NET Core 2.x installed?

On that note, if you want to see it in action:

docker run -it mcr.microsoft.com/dotnet/core/sdk:3.1 bash
dotnet tool install swashbuckle.aspnetcore.cli --global
export PATH="$PATH:/root/.dotnet/tools"
swagger

I'm still dealing with this by using the environment variable in DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2 but it should just be a matter of adding

<RollForward>Major</RollForward>

to the CLI project file.

See the Entity Framework project file for an example:
https://github.com/dotnet/efcore/blob/7d5c2aa7395989d1670dabd54e7e72e7fba57e17/src/dotnet-ef/dotnet-ef.csproj#L30

I cloned the repository and built with RollForward and tested it in a Docker container with only 3.1 installed and it worked. I didn't test back compat to 2.1 though. I'm happy to submit a pull request, but it's literally just that one line.

It looks like there is an issue with the CLI and it actually requires .NET Core 2.1 installed. I modified the example provided by @ericl85 in the following way in order to get the CLI working:

docker run -it mcr.microsoft.com/dotnet/core/sdk:3.1 bash

wget https://packages.microsoft.com/config/ubuntu/19.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb ;
dpkg -i packages-microsoft-prod.deb ;
apt-get update ;
apt-get install -y aspnetcore-runtime-2.1 ;
dotnet tool install swashbuckle.aspnetcore.cli --global ;
export PATH="$PATH:/root/.dotnet/tools" ;
swagger

Closing in favor of #1699, which captures all of the outstanding compatibility issues. That issue is being addressed as a top priority

Was this page helpful?
0 / 5 - 0 ratings