Score:0

Why do I get the error "The command could not be loaded" when running `dotnet` commands after installing the .NET SDK?

in flag

I followed the official instructions to install the latest version of the .NET SDK. I chose the "Package manager (Microsoft feed)" method. After completing these instructions and running dotnet --version, I get the following output:

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.

Download a .NET SDK:
https://aka.ms/dotnet/download

Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found

I read both of those web pages, but they don't provide me with solutions. One brings me back to the beginning of the process for installing the .NET SDK. The other talks about how SDK resolutions works, mostly when applications are run. But this doesn't help me with the CLI tool dotnet.

I found it interesting that if I ran dotnet --info, I got the following output, which confirms that it thinks no SDK is installed:

Host:
  Version:      7.0.9
  Architecture: x64
  Commit:       8e9a17b221

.NET SDKs installed:
  No SDKs were found.

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

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/usr/lib/dotnet]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

I think this is strange because if I use APT to check which packages I have installed, I see output that makes it look like after I followed the official install instructions, I did indeed have one version of the SDK installed (7.0.109):

$ sudo apt list --installed | grep dotnet

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

dotnet-apphost-pack-7.0/jammy-updates,jammy-security,now 7.0.109-0ubuntu1~22.04.1 amd64 [installed,automatic]
dotnet-host-7.0/jammy-updates,jammy-security,now 7.0.109-0ubuntu1~22.04.1 amd64 [installed,automatic]
dotnet-hostfxr-7.0/jammy-updates,jammy-security,now 7.0.109-0ubuntu1~22.04.1 amd64 [installed,automatic]
dotnet-runtime-7.0/jammy-updates,jammy-security,now 7.0.109-0ubuntu1~22.04.1 amd64 [installed,automatic]
dotnet-sdk-7.0/jammy,now 7.0.306-1 amd64 [installed]
dotnet-targeting-pack-7.0/jammy-updates,jammy-security,now 7.0.109-0ubuntu1~22.04.1 amd64 [installed,automatic]
Score:0
in flag

My issue was that I had installed version 7 of the .NET SDK through a mix of Microsoft feed packages and Ubuntu feed packages. This is described in more detail in their APT troubleshooting steps. I was using 22.04 via WSL so this problem applied to me.

My solution was to follow their recommended approach for people who don't rely on the Microsoft feed for any reason, which was to completely remove the Microsoft feed from my system and then follow their instructions for installing using the Ubuntu feed. After I did this, my dotnet --info output shows the installed SDK:

.NET SDK:
 Version:   7.0.109
 Commit:    3e9283a8e9

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  23.04
 OS Platform: Linux
 RID:         ubuntu.23.04-x64
 Base Path:   /usr/lib/dotnet/sdk/7.0.109/

Host:
  Version:      7.0.9
  Architecture: x64
  Commit:       8e9a17b221

.NET SDKs installed:
  7.0.109 [/usr/lib/dotnet/sdk]

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

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/usr/lib/dotnet]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Because I was using 22.04 but I wanted to install and use the latest non-preview version of the SDK (which is 7 as of today), I had to first upgrade to 23.04. I did this by following the instructions I found on a 3rd party website, which were to run sudo do-release-upgrade. When I did this, it told me that I was already running the latest version I could upgrade to, unless I tweaked a config file and tried again. So I followed the instructions, then tried the upgrade again, and then I was running 23.04 so that I could do the above steps to get .NET SDK 7 installed.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.