Search code examples
asp.net.net-7.0ubuntu-22.04.net-sdk

Ubuntu .Net 7 Install Can't Find SDK


I am running Ubuntu 22.04 and trying to install .NET 7.0.5

I have tried multiple different methods of installing .NET 7, none of them seem to allow me to use the dotnet build or dotnet publish command.

It appears to be some kind of issue with Ubuntu not recognizing that my SDKs are installed.

dotnet publish -c Release -r linux-x64 --self-contained false

You must install or update .NET to run this application.

App: /usr/share/dotnet/sdk/7.0.302/dotnet.dll
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '7.0.5' (x64)
.NET location: /usr/share/dotnet/

No frameworks were found.

I tried to show the dotnet version:

root@localhost:~# dotnet --version
    The command could not be loaded, possibly because:
      * You intended to execute a .NET application:
          The application '--version' does not exist.
      * You intended to execute a .NET SDK command:
          No .NET SDKs were found.

Dotnet information:

root@localhost:~# dotnet --info

    Host:
      Version:      7.0.5
      Architecture: x64
      Commit:       8042d61b17

    .NET SDKs installed:
      No SDKs were found.

    .NET runtimes installed:
      Microsoft.AspNetCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]

    Other architectures found:
      None

    Environment variables:
      Not set

    global.json file:
      Not found

Where is dotnet according to my system?

root@localhost:~# whereis dotnet
        dotnet: /usr/bin/dotnet /usr/lib/dotnet /etc/dotnet /usr/share/dotnet 
                /usr/share/man/man1/dotnet.1.gz

Could my PATH not be correctly set or something? How would I fix this issue?

Thanks!


Solution

  • Look at the paths carefully in the error messages:

    App: /usr/share/dotnet/sdk/7.0.302/dotnet.dll
    Architecture: x64
    Framework: 'Microsoft.NETCore.App', version '7.0.5' (x64)
    .NET location: /usr/share/dotnet/
    

    This says the SDK is supposed to be at /usr/share/dotnet.

        .NET SDKs installed:
          No SDKs were found.
    
        .NET runtimes installed:
          Microsoft.AspNetCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
          Microsoft.NETCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
    

    This says the runtimes are at /usr/lib/dotnet/, and the SDKs are not found.

    You have somehow installed some parts of .NET in /usr/share/dotnet and others in /usr/lib/dotnet. That's not going to work, because .NET expects everything to be in a single location - either /usr/lib/dotnet/ or /usr/share/dotnet. Because parts are installed in different locations, .NET gets completely confused and gives you these misleading errors.

    I suspect this is because you installed the .NET packages from two different providers - the runtime is from the Ubuntu repository (and installs at /usr/lib/dotnet) while the SDK is from the Microsoft repository (and installs at /usr/share/dotnet).

    To fix this, I would:

    • Uninstall all .NET packages: sudo apt remove 'dotnet*' 'aspnet*' 'netstandard*'
    • Remove the Microsoft repository: sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
    • Install .NET (which should pull down the SDK and the runtime from the Ubuntu repository): sudo apt install dotnet-sdk-7.0

    For more details, and some other solutions to this problem, see https://learn.microsoft.com/en-us/dotnet/core/install/linux-package-mixup?pivots=os-linux-ubuntu#solutions