.NET SDK를 설치한 후 `dotnet` 명령을 실행할 때 "명령을 로드할 수 없습니다" 오류가 발생하는 이유는 무엇입니까?

.NET SDK를 설치한 후 `dotnet` 명령을 실행할 때 "명령을 로드할 수 없습니다" 오류가 발생하는 이유는 무엇입니까?

나는 따라 갔다공식 지침최신 버전의 .NET SDK를 설치합니다. 저는 "패키지 관리자(Microsoft 피드)" 방법을 선택했습니다. 이 지침을 완료하고 실행하면 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.

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

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

나는 그 두 웹 페이지를 모두 읽었지만 그들은 나에게 해결책을 제공하지 않습니다. 하나는 .NET SDK 설치 프로세스의 시작 부분으로 돌아갑니다. 다른 하나는 주로 애플리케이션이 실행될 때 SDK 해상도가 작동하는 방식에 대해 설명합니다. 하지만 이는 CLI 도구 사용에 도움이 되지 않습니다 dotnet.

dotnet --info을 실행하면 다음과 같은 출력이 표시되어 SDK가 설치되지 않은 것으로 확인된다는 점이 흥미로웠습니다 .

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

APT를 사용하여 내가 설치한 패키지를 확인하면 공식 설치 지침을 따른 후 실제로 SDK의 한 버전(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]

답변1

내 문제는 Microsoft 피드 패키지와 Ubuntu 피드 패키지를 혼합하여 .NET SDK 버전 7을 설치했다는 것입니다. 이에 대한 자세한 내용은 해당 문서에 설명되어 있습니다.APT 문제 해결 단계. 저는 WSL을 통해 22.04를 사용하고 있었기 때문에 이 문제가 발생했습니다.

내 솔루션은 어떤 이유로든 Microsoft 피드에 의존하지 않는 사람들을 위해 권장되는 접근 방식을 따르는 것이었습니다. 즉, 내 시스템에서 Microsoft 피드를 완전히 제거한 다음 Ubuntu 피드를 사용하여 설치하기 위한 지침을 따르는 것이었습니다. 이 작업을 수행한 후 dotnet --info출력에는 설치된 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

22.04를 사용하고 있었는데 미리보기가 아닌 최신 버전의 SDK(현재 7)를 설치해서 사용하고 싶어서 먼저 23.04로 업그레이드를 해야 했습니다. 저는 제3자 웹사이트에서 찾은 지침에 따라 이 작업을 수행했습니다 sudo do-release-upgrade. 이 작업을 수행했을 때 구성 파일을 조정하고 다시 시도하지 않는 한 업그레이드할 수 있는 최신 버전을 이미 실행하고 있다는 메시지가 표시되었습니다. 그래서 지침에 따라 업그레이드를 다시 시도한 다음 위의 단계를 수행하여 .NET SDK 7을 설치할 수 있도록 23.04를 실행했습니다.

관련 정보