2

I upgraded Visual Studio Community to the final release, and it stopped working. Specifically, I could generate a new project, but when I try to load it, it gave me an error

Critical Project 'SdkTest' load failed| [MSB4236] The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. ...\SdkTest.csproj

Even though build and run worked fine

I ran "repair" on VS2022, and it seems to be working now from Visual Studio. However, dotnet --info doesn't show any SDKs; only runtime; and dotnet build or dotnet new give an error:

C:\Code>dotnet new console -o myapp
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
   * You intended to execute a .NET program:
     The application 'new' does not exist.
   * You intended to execute a .NET SDK command:
     It was not possible to find any installed .NET SDKs.
     Install a .NET SDK from:
       https://aka.ms/dotnet-download

I even reinstalled .NET 6 and I see it in the list of applications (along with older SDKs). I checked the path, and I see everything that I expect to see:

C:\Program Files (x86)\dotnet\
C:\Program Files\dotnet\
C:\Users\me\.dotnet\tools

I am running Windows 11.

Felix
  • 9,248
  • 10
  • 57
  • 89
  • 1
    `Program files` should be before `Program files (x86)`, it's known bug. [Fix](https://github.com/dotnet/installer/issues/12616#issuecomment-965401018) – JL0PD Nov 12 '21 at 07:48
  • @JL0PD - do you want to put it as answer? I'll happily accept. I was googling with all kind of search words - and never stumbled onto that github issue – Felix Nov 12 '21 at 08:08

2 Answers2

6

It's known bug in VS2022 installation.

Problem is that dotnet you access is located inside Program Files(x86)/dotnet, but all sdk's are located in Program Files/dotnet. You simply need to edit PATH environment variable so Program Files/dotnet goes before Program Files(x86)/dotnet. If you don't see Program Files(x86)/dotnet in user environment variable (which is likely to happen) then edit system environment variable (located below)

Example with screenshots: https://stackoverflow.com/a/44272417/10339675

JL0PD
  • 3,698
  • 2
  • 15
  • 23
  • Incidentally, while I was waiting for this answer - I downloaded and installed "dotnet-install scripts" which is generally used for CI servers. It installed another `dotnet` into `AppData\Local\Microsoft\dotnet\` and added it to the PATH first. This also made it work. Obviously, your answer is better approach - and it explains why I had a problem I was having. Thank you – Felix Nov 12 '21 at 17:28
  • 1
    Also, a good explanation from Microsoft here: https://stackoverflow.com/questions/63746838/net-sdks-not-installing-correctly – Felix Nov 13 '21 at 19:31
0

edit Path environment variables, and in the editing window move up "ProgramFiles/dotnet"