[Visual Studio error] error cannot find the specified SDK "Microsoft

[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:

image-20230705112230134

Error analysis and resolution

Open the project configuration file and find that this sdk .csprojis used in this location .Microsoft.NET.Sdk.Web

image-20230705112412510

The reason for the error is obvious, that is, the system cannot find Microsoft.NET.Sdk.Webthe storage path of the SDK.

Use cmd to open and execute dotnet --infothe command, the output information is as follows:

image-20230705113131540

Sure enough, the system did not find the SDK.

Then you can only see if there is any problem with the environment variable.

image-20230705114635360

image-20230705114835400

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:

image-20230705115426439

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.

image-20230705120022596

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

image-20230705120418785

Guess you like

Origin blog.csdn.net/guigenyi/article/details/131552960