[Visual Studio 2022 error] error: The specified SDK "Microsoft.NET.Sdk.Web" cannot be found
Problem Description:
After installing VS2022 on the new computer, this error was reported after opening the solution of the existing project, and all projet files failed to load, as shown in the figure:
Error analysis and resolution
Open the project configuration file and find that this sdk .csproj
is used in this location .Microsoft.NET.Sdk.Web
The reason for the error is obvious, that is, the system cannot find Microsoft.NET.Sdk.Web
the storage path of the SDK.
Use cmd to open and execute dotnet --info
the command, the output information is as follows:
Sure enough, the system did not find the SDK.
Then you can only see if there is any problem with the environment variable.
Found that there are two dotnet paths.
Blindly guess the reason for the error: the two dotnet paths conflict, the system defaults to the above path to find the sdk, but cannot find it.
Let's move the following C:\Program Files\dotnet\
up to try:
Then click OK to close the window.
Close the original cmd window.
Re-open a cmd and enter the command:
dotnet --info
The running results are as follows, and the SDK has been found.
Note :
1. After setting the environment variable, you need to save and close the window, and open it again in cmd to take effect.
2. I estimate that the donet path can also be deleted.
Re-open the solution with VS, and the project is loaded successfully, as shown in the figure