You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法从global.json找到兼容SDK版本,npm与dotnet命令异常求助

Troubleshooting .NET Core SDK 2.1.0 Not Found Error

Let’s break down the key checks and configurations you need to verify to resolve this SDK mismatch error:

1. Confirm the SDK is actually installed

First, make sure the exact .NET Core 2.1.0 SDK is present on your machine:

  • Open a fresh Command Prompt or PowerShell window (cached environment state can cause false negatives)
  • Run this command to list all installed SDKs:
    dotnet --list-sdks
    
  • Look for 2.1.0 in the output. Note: this checks for SDKs, not just runtimes. If it’s missing, re-download and install the 2.1.0 SDK (double-check you’re grabbing the SDK installer, not the runtime-only package).

2. Inspect your PATH environment variable

The PATH variable tells your system where to find the dotnet CLI. Here’s what to verify:

  • Open System Properties > Advanced > Environment Variables
  • Under System Variables, locate and edit the PATH entry:
    • Ensure the path to your dotnet installation (typically C:\Program Files\dotnet\) is present. If you installed both x86 and x64 versions, make sure the architecture matching your 2.1.0 SDK comes first in the PATH order. For example, if you have the x64 2.1.0 SDK, C:\Program Files\dotnet\ should appear before C:\Program Files (x86)\dotnet\.
  • Close and reopen your terminal after making changes to apply the updates.

3. Check the DOTNET_ROOT environment variable

If you’ve set the DOTNET_ROOT system variable, it overrides the default dotnet installation path:

  • In Environment Variables, check if DOTNET_ROOT exists under System Variables.
  • If it does, verify it points to the correct root directory of your dotnet installation (e.g., C:\Program Files\dotnet\). If it’s pointing to a directory without the 2.1.0 SDK, either update the path or delete the variable to let the system use the default location.

4. Validate your global.json file

Your project’s global.json enforces the use of SDK 2.1.0. Double-check:

  • Ensure the file has no syntax errors (missing commas, incorrect quotes, etc.). Your current content looks valid, but confirm it’s exactly:
    { "sdk": { "version": "2.1.0" } }
    
  • If you have a newer 2.1.x SDK installed (like 2.1.818, a common patch version for 2.1), you can modify the version field to 2.1.x to allow using the latest compatible SDK in the 2.1 series, which might resolve the issue if the exact 2.1.0 SDK is problematic:
    { "sdk": { "version": "2.1.x" } }
    

5. Verify your terminal architecture

If you installed the x64 SDK but are using an x86 terminal, the CLI will look for the x86 version of the SDK (which you might not have installed):

  • Run dotnet --info in your terminal. Look for the "Architecture" field to confirm it matches your installed SDK’s architecture.
  • If there’s a mismatch, open the correct terminal (e.g., use the "x64 Native Tools Command Prompt" instead of x86, or the standard Command Prompt on a 64-bit system).

6. Clear cached data

Cached files can sometimes cause conflicts:

  • In your project directory, run:
    dotnet clean
    
  • Then clear the NuGet cache with:
    dotnet nuget locals all --clear
    
  • Try your original commands (dotnet build -c Release -o ./app and npm install) again after this.

7. Check Visual Studio configurations (if using VS)

If you’re working in Visual Studio:

  • Go to Tools > Options > Projects and Solutions > .NET Core and ensure the correct SDK versions are recognized.
  • Right-click your project > Properties > Application and confirm the Target Framework is set to .NET Core 2.1.
  • Verify you have the .NET Core 2.1 development workload installed via the Visual Studio Installer.

After working through these steps, open a fresh terminal, navigate to your project directory, and run dotnet --version to confirm it’s picking up the 2.1.0 SDK. If that works, your original commands should run without the error.

内容的提问来源于stack exchange,提问作者Jammer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:11:51