2

I have a problem with VS Code .net 5 settings.

Error MSB3971: The reference assemblies for ".NETFramework,Version=v5.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK.

Some time ago I was using .net core 3 recently I wanted to move to the newest version.

  1. I have installed the latest version of the SDK -> https://dotnet.microsoft.com/download/dotnet/5.0
  2. I updated VS Code to the latest version
  3. I started a brand new project in .net 5

I was looking for a solution to my problem on the internet, but nothing works.

Powershell dotnet version:

dotnet --version
5.0.401
dotnet --info   
Zestaw .NET SDK (odzwierciedlenie dowolnego pliku global.json):
 Version:   5.0.401
 Commit:    4bef5f3dbf

Środowisko uruchomieniowe:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.401\

Host (useful for support):
  Version: 5.0.10
  Commit:  e1825b4928

.NET SDKs installed:
  2.1.700 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.2.202 [C:\Program Files\dotnet\sdk]
  5.0.401 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Visual Studio Code Version:

version: 1.60.2

Info about Visual Studio Code

The contents of the project.csproj file

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
  </ItemGroup>

</Project>

I have the latest SDK and VS Code, I don't know what else I can do to make it work.


I uninstall all versions of .net and install only 5.0. Now i have new error

error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.

After I reinstall .NET I got this from terminal:

dotnet --info
Zestaw .NET SDK (odzwierciedlenie dowolnego pliku global.json):
 Version:   5.0.401
 Commit:    4bef5f3dbf

Środowisko uruchomieniowe:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.401\

Host (useful for support):
  Version: 5.0.10
  Commit:  e1825b4928

.NET SDKs installed:
  5.0.401 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
Mszarna
  • 83
  • 1
  • 8
  • Does this answer your question? [The reference assemblies for framework .NETCore, Version=v5.0 were not found](https://stackoverflow.com/questions/49268779/the-reference-assemblies-for-framework-netcore-version-v5-0-were-not-found) – Max Oct 07 '21 at 17:53
  • Weird, there is no .Net Framework version 5!!! – phuzi Oct 08 '21 at 13:00
  • Does this answer your question? [Error: The reference assemblies for .NETFramework,Version=v5.0 were not found](https://stackoverflow.com/questions/66194936/error-the-reference-assemblies-for-netframework-version-v5-0-were-not-found) – phuzi Oct 08 '21 at 13:03
  • Please edit your *.csproj file in a notepad and check whether the very first line is : If yes, then double-check you've installer the Aspnet Core version of the sdk here https://dotnet.microsoft.com/download/dotnet/5.0 – Romka Oct 08 '21 at 13:22
  • @Romka I have: `.NET SDKs installed: 5.0.401 [C:\Program Files\dotnet\sdk]` `.NET runtimes installed: Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]` – Mszarna Oct 08 '21 at 13:35
  • @phuzi I have the latest versions of VSCode and .NET. And this is recommended to be fixed in this question. – Mszarna Oct 08 '21 at 13:38

3 Answers3

6

I struggled with this problem for a long time. Here is a list of things that need to be checked.

  1. Remove all SDKs from your computer. - Find in the control panel "Programs and Features" then delete all Microsoft .NET Runtime - x.x.xx, Microsoft .NET SDK x.x.x

  2. Install newest .NET SDK and Runtime - i use this site

  3. Check your PATH - Check if the path with the environment variables in windows contains C:\Program Files\dotnet

  4. !! Check MSBuildSDKsPath Environment Variable - It turned out that installing the new SDK does not change the information in the environment paths. I still had the old version listed there and after uninstalling everything, I got a message saying that 'Microsoft.NET.Sdk.Web' could not be found.

    Check the value of the MSBuildSDKsPath variable. The proper value for me was x C:\Program Files\dotnet\sdk\5.0.401\Sdks Environment Variable

Mszarna
  • 83
  • 1
  • 8
5

In my case that was caused by global.json in a root folder that had lower SDK hardcoded. Probably worth to add this to previous answer.

Dmitry Gusarov
  • 1,469
  • 15
  • 22
  • 1
    Unbelievable, but true! I copied global.json to the D: drive root and started to see the same. – Andrei Drynov Sep 08 '22 at 16:33
  • Wow... this answer fixed at least 3 completely independent issues around using .net with visual studio, vscode, vscode extension. Just because of a global.json file I put in C:\ folder. Thank you! – Shubham Jan 14 '23 at 21:13
  • Even though I had a global.json file that specified .net6, in the root of the project, it still overruled those settings by a global.json that was 3 folders up. – John Pankowicz Apr 12 '23 at 15:19
0

Deleting the bin, obj and .vs folder and then opening and building the application worked for me.

Baga
  • 1,354
  • 13
  • 24