I could get the .NET 7 SDK installation on Xubuntu 22.04 working by adding the file /etc/apt/preferences
as described here after having dotnet6
installed from official Ubuntu packages:
Package: dotnet-sdk-7.0
Pin: origin "packages.microsoft.com"
Pin-Priority: 999
I also reinstalled .NET 6 SDK (sudo apt reinstall dotnet-sdk-6.0
) by adding it to the file:
Package: dotnet-sdk-7.0 dotnet-sdk-6.0
Pin: origin "packages.microsoft.com"
Pin-Priority: 999
However, dotnet run --framework net6.0
in a .NET 6 project stopped working:
dotnet run --framework net6.0
Building...
You must install or update .NET to run this application.
App: /home/alexzeitler/src/myproject/bin/Debug/net6.0/myproject
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '6.0.0' (x64)
.NET location: /usr/share/dotnet
The following frameworks were found:
7.0.2 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x64&rid=ubuntu.22.04-x64
I added this global.json
in the project folder:
{
"sdk": {
"version": "6.0.405",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}
dotnet --list-sdks
:
6.0.405 [/usr/share/dotnet/sdk]
7.0.102 [/usr/share/dotnet/sdk]
I can change my csproj
to this:
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
That way things will work when using dotnet run --framework net7.0
but I don't want (read: can't) to touch all projects on my machine.
I didn't have prior .NET 7 SDK previews installed as suggested by answers to SDK Resolver Failure - Net 7 - Net 6.