got error " The "RazorGenerate" task failed unexpectedly. " .After Updating to VS 16.8 and upgrade to .net 5.. the core version target is Core 2.2

.Net Core

.Net Core Problem Overview


enter image description here

When Build Project. Error The "RazorGenerate" task failed unexpectedly. .Net Core 2.2

.Net Core Solutions


Solution 1 - .Net Core

The fix for me was to introduce a new System Environment Variable with the Key "DOTNET_HOST_PATH" and the value "dotnet" and then to restart Visual Studio.

Solution 2 - .Net Core

I did 3 steps to get it to build AND to get the ( ~/ ) variable to work.

  1. Open cmd and write this: setx DOTNET_HOST_PATH "%ProgramFiles%\dotnet\dotnet.exe"
  2. Open C:\Program Files\dotnet\sdk in here delete the folder: NuGetFallbackFolder
  3. Restart your pc!

Solution 3 - .Net Core

It worked on the build server, after I added this Nuget package:

Microsoft.NET.Sdk.Razor

Since I added the Net.SDK.Razor package, it builds successfully.

I had also added Microsoft.AspNetCore.Razor.Design, but only Microsoft.NET.Sdk.Razor is actually needed.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNader Gharibian FardView Question on Stackoverflow
Solution 1 - .Net CoreRob PowellView Answer on Stackoverflow
Solution 2 - .Net CoreYasser BazrforooshView Answer on Stackoverflow
Solution 3 - .Net CoreMajid AzarniushView Answer on Stackoverflow