Visual studio 2019 v16.6 can't build .net5 console application and raise errors: .NETFramework,Version=v5.0 were not found

Viewed 18331

Development Environment:

  • Visual studio 2019 v16.6.2 is installed
  • .Net5 preview 5 is installed

Microsoft.NETCore.App 5.0.0-preview.5.20278.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

  • Enable the designer in Visual Studio
Tools > Options > Environment > Preview Features and select the Use the preview Windows Forms designer for .NET Core apps option. > re-start vs

I followed the instructions in this answer

I created a demo console project in .net5

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>  
</Project>

Then build and run using dotnet cli is ok

dotnet build  #ok
dotnet run # ok

Trying to build the project in visual studio fail with errors

Error MSB3644 The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Error NETSDK1005 Assets file 'F:\projects\Net5Demo\obj\project.assets.json' doesn't have a target for '.NETFramework,Version=v5.0'. Ensure that restore has run and that you have included 'net50' in the TargetFrameworks for your project.

What I missed to build and run the project using vs 2019 v16.6.2 ?

5 Answers

As per https://dotnet.microsoft.com/download/dotnet/5.0 it looks like you also need VS 2019 16.8 preview 3 for it to recognize it.

Edit: I was having the same issue and after I installed VS 2019 16.8 preview 3 it started showing the option to use .NET 5.0.

Maybe you need to enable previews in Visual Studio:

Go to Tools > Options and enter Preview Features in the left panel.

Then in the right panel enable Use previews of the .NET Core SDK (requires restart)

enter image description here

  • Update Visual Studio to Visual Studio 2019 version 16.7 (released on Aug 5,2020 with support c# 9)
 help -> check for updates -> visual studio installer is displayed -> click update
  • Enable the designer in Visual Studio 2019 (as in OP).
  • Update to SDK 5.0.100-preview.7.

Just to check c# 9 availability, in the developer Command Prompt, type the command:

csc -langversion:?

You get:

Supported language versions:
default
1
2
3
4
5
6
7.0
7.1
7.2
7.3
8.0 (default)
9.0
latestmajor
preview
latest

The list above include 9.0 and you LangVersion can be defined as 9.0: The Console project with c# 9 support, can be:

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>net5.0</TargetFramework>
  <LangVersion>9.0</LangVersion> 
</PropertyGroup>

Now VS 2019 v16.7 can compile c# 9 in NET 5 successfully and IDE support C# 9.

Update: Sep15,2020

Vs 2019 16.7.3 is supporting only Preview7.

Full version
    5.0.100-preview.7.20366.6
Visual Studio support
    Visual Studio 2019 (v16.7, latest preview)
    Visual Studio 2019 for Mac (v8.7 preview)

In Download .Net 5 page, you can find the official VS2019 support. It seems that 16.7.3 is supporting only preview7.

Have you downloaded the x64 or the x86 version of the SDK?

You may try to download the preview 6.

My VS is 16.7.3 (the latest). But, when I install, SDK 5.0.100-preview.8, I don't see .Net 5.0 on my Target framework. But, after uninstalling it and reinstalling SDK 5.0.100-preview.7, I could see it.

Related