1

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.

Alexander Zeitler
  • 11,919
  • 11
  • 81
  • 124
  • Have you tried looking into asdf with https://github.com/emersonsoares/asdf-dotnet-core? – Ben Wong Jan 31 '23 at 21:36
  • 1
    No, didn't try it so far. I'm not sure if this doesn't create another rabbit hole: https://youtrack.jetbrains.com/issue/RIDER-56411/Rider-fails-to-find-dotnet-sdk-installed-using-asdf-asdf-dotnet-core.#focus=Comments-27-6570333.0-0 – Alexander Zeitler Jan 31 '23 at 21:41
  • 1
    Also this one... https://github.com/emersonsoares/asdf-dotnet-core/issues/21 – Alexander Zeitler Jan 31 '23 at 21:47
  • 1
    That's how I fixed it: https://alexanderzeitler.com/articles/fixing-my-bricked-dotnet-sdk-6-installation-on-xubuntu-ubuntu-after-dotnet-7-sdk-installation/ – Alexander Zeitler Feb 01 '23 at 08:17

0 Answers0