I'm trying to run the dotnet tool Swashbuckle.AspNetCore.Cli (5.6.3) in a Azure Devops build agent with only .NET 5

That doesn't work and I get the following error:

It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '3.0.0' was not found.
  - The following frameworks were found:
      5.0.9 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.AspNetCore.App]

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

I see that indeed there is no dll for .NET 5:

enter image description here

But I don't get it. The issue will be fixed if I have .NET Core 3.0 (or 3.1) installed, but why is that? What can't we run a tool like this on the .NET 5 runtime?

.NET 5 is the successor of .NET Core 3, so I expected that .NET Core 3 binaries are could be used by .NET 5.

PS: I know Swashbuckle.AspNetCore.Cli 6.x has a .NET 5 dll, but I need Swashbuckle v5 behavior and I'm trying to understand the underlying issue.

1

There are 1 best solutions below

1
On BEST ANSWER

Actually this is only partially true - each major release of new .net core framework (3.0.0, 5.0.0) introduces multiple breaking changes. So runtimes are compatible with each other on minor and patch level only.

Because of that if you chose to target your executable (.exe or .dll nowadays) to .net 3.0, you can run it on installed 3.1.0 or 3.0.2 runtime which will be picked up automatically. However, if you have only 5.0 installed, there will be the error as you wrote.

This behavior is configurable by roll forwarding property which you can specify on project level:

<PropertyGroup>
  <RollForward>LatestMinor</RollForward>
</PropertyGroup>

You can also specify it as an argument (your case with cli)

dotnet myapp.dll --roll-forward LatestMinor

If there is no RollForward property specified, the default behavior is what I described above. However, you can try LatestMajor which should chose the newest major version of runtime installed (5.0), even if the target one (3.0) is also available. See the full list of allowed RollForward values on MS documentation page