I cant get Visual studio to use .NET 5.
The following are my current configuration: Visual Studio Professional 2019 version: 16.7.6
.NET sdk: dotnet-sdk-5.0.100-preview.7.20366.6-win-x64 (see image for more info)
Visual Studio settings: I have selected "Use previews of the .NET Core SDK" in VS (See image)
Possible source of my problem: I accidentally installed preview 8 of .NET 5, this version don't support my version of Visual Studio. I removed this version and installed the correct one (preview 7 should have support for VS 16.7, see: https://dotnet.microsoft.com/download/dotnet/5.0)
These are the steps I take to reproduce my problem:
in visual studio I do the following to create a .net 5 project (blazor project):
6.the project is now created but a error message is instantly displayed "the reference assemblies for .NETFramework, Version=v5.0 were not found. ..." (see image)
7.right click on the project -> Properties 8. "Target framework" are now blank, If i open the dropdown only .Net framework versions are available (see image)
Other information that might have value: If i creat a new project and select .Net core 3.1 instead of .net 5 everything is working fine. Doing this alows me to see items other than .Net framework in the "Target frameworks" dropdown, .NET 5 are however still missing. (see image)
If i go to "Add or remove programs" .Net 5 of the correct version are listed. (it is also the only listed version of .NET 5)
If i look at the system path it is correctly set to: "C:\Program Files\dotnet"
Why is this happening? how can i get .net 5 to correctly show in this list?
#Update 1: After installing Visual studio 16.8.0 Preview 5.0 the problem still persists .NET 5 can't be used. If i look at Dependencies it is clear that something is wrong, non of the entries under Dependencies -> Assemblies are found/has a value (see image)
#Update 2: finally found a solution 4 this problem using global.json, see my own answer for more details
Finally found a solution for this problem. As VS somehow is loosing track of what .Net version it should use I needed to "force" the program to use the intended version. This need to be done on a "per solution basis" and are done by adding a global.json file to the root of the solution that contains info about what exact version is needed.
This can be done by:
dotnet new globaljson
dotnet --version
(or dotnet --info
if you got multiply entry's and need to find a specific one)
Doing this solved my problem and VS can now correctly find my .Net 5 installation. This also allowed me to VS 2019 version 16.7.6 with .net 5.0 preview 7 (no VS preview needed). It is worth mentioning that the VS setting "Use previews of .net Core" mentioned in the original post still need to be activated (in non-preview versions of VS)
EDIT #1:
Here is where you find more info about the global.json: https://learn.microsoft.com/en-us/dotnet/core/tools/global-json?tabs=netcore3x
EDIT #2: .net 6
The same machine had the very same problem when going to .net 6, older versions where showing in vs22 but not .net 6. using a global.json to target .net6 did the trick here.
You must upgrade your VS version. .NET 5 is compatible with version 16.8 of Visual Studio. If you are using VSCode instead, use a global.json file to specify the dotnet version you want to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With