I kept getting his error after installing the required version of dotnet. Here's how I solved it: set user environment viriable DOTNET_ROOT to C:\Program Files\dotnet.

How I located the cause:

When I run dotnet --info in powershell, it printed these:

Host:
  Version:      9.0.9
  Architecture: x64
  Commit:       893c2ebbd4
  RID:          win-x64

.NET SDKs installed:
  No SDKs were found.

.NET runtimes installed:
  Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  DOTNET_ROOT       [C:\Users\myusername\Tools\dotnet]

global.json file:
  Not found

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

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

The DOTNET_ROOT was wrong.
So I opened DOTNET_ROOT, C:\Users\myusername\Tools\dotnet, this folder stored version 8, no wonder it kept asking me to update no matter how many times I've updated it.

The solution is:

  1. Press Win + E to open File Explorer.
  2. Right-click on This PC option on the left and select Properties.
  3. Scroll down to the Related settings section and then click the Advanced system settings option.
  4. Click the Environment Variables button.

Make sure the value of variable DOTNET_ROOT is C:\Program Files\dotnet, and make sure there is no other dotnet path in Path, check them in both user and system variables.

Reference

  1. How to Fix the Windows “To Run This Application, You Must Install .NET Core” Error
文章目录