Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RazorTagHelper - DOTNET_HOST_PATH is not set #28333

Closed
celoko-cintra opened this issue Nov 11, 2020 · 63 comments
Closed

RazorTagHelper - DOTNET_HOST_PATH is not set #28333

celoko-cintra opened this issue Nov 11, 2020 · 63 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed Servicing-consider Shiproom approval is required for the issue
Milestone

Comments

@celoko-cintra
Copy link

After updating VS 2019 16.8.0 I'm facing this error on compilation on any project:

Web C# .net core 2.2

Erro MSB4018 Falha inesperada da tarefa "RazorTagHelper".
System.InvalidOperationException: DOTNET_HOST_PATH is not set
em Microsoft.AspNetCore.Razor.Tasks.DotNetToolTask.get_DotNetPath()
em Microsoft.AspNetCore.Razor.Tasks.DotNetToolTask.GenerateFullPathToTool()
em Microsoft.Build.Utilities.ToolTask.ComputePathToTool()
em Microsoft.Build.Utilities.ToolTask.Execute()
em Microsoft.AspNetCore.Razor.Tasks.DotNetToolTask.Execute()
em Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
em Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() QRPlus C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor.design\2.2.0\build\netstandard2.0\Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets 79

Anyone knows whats is going on?

@Lanticee
Copy link

I got same problem too. anyone can help?

@terrier-tom
Copy link

terrier-tom commented Nov 11, 2020

I doubt this is a permanent or proper solution, but I got rid of the error by adding a system environment variable named DOTNET_HOST_PATH with a value of dotnet. There are several ways in Windows to get to the spot where you can add system environment variables. Either use the Windows search (enter system environment variable in the search box) or get there via Control Panel -> System -> Advanced System Properties and then Environment Variables button.

All I can say is by doing the above my program would again build.

NOTE: I did have to close down visual studio and reload it after adding the variable in order for things to start working.

EDIT: While the manual addition of DOTNET_HOST_PATH did get my project to build, there were issues when I ran it. The paths for all of the static files within wwwroot were incorrect; they all had an unwanted segment in the path ("~/").

@Yavari
Copy link

Yavari commented Nov 11, 2020

We are using ASP.NET Core 2.2 with .NET Framework 4.6.1 and I get the same exception with Visual Studio 2019 16.8.0.

Severity Code Description Project File Line Suppression State
Error MSB4018 The "RazorGenerate" task failed unexpectedly.
System.InvalidOperationException: DOTNET_HOST_PATH is not set
at Microsoft.AspNetCore.Razor.Tasks.DotNetToolTask.get_DotNetPath()
at Microsoft.AspNetCore.Razor.Tasks.DotNetToolTask.GenerateFullPathToTool()
at Microsoft.Build.Utilities.ToolTask.ComputePathToTool()
at Microsoft.Build.Utilities.ToolTask.Execute()
at Microsoft.AspNetCore.Razor.Tasks.DotNetToolTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() <HOME_PATH>.nuget\packages\microsoft.aspnetcore.razor.design\2.2.0\build\netstandard2.0\Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets 131

@duweiblog
Copy link

目录路径:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor.design\2.2.0\build\netstandard2.0\

删除上面目录以下两个文件:
Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets
Microsoft.AspNetCore.Razor.Design.props

ps:文件路径因人而异

@mcurko
Copy link

mcurko commented Nov 11, 2020

Microsoft's own sample app https://github.com/Azure-Samples/service-fabric-dotnet-quickstart/ wont compile after VS was upgraded (.NET 4.7.2 in these projects).

@olivermue
Copy link

Added the following environment variable to my user environment to make it build again:
DOTNET_HOST_PATH
%ProgramFiles%\dotnet\dotnet.exe

@tolbxela
Copy link

tolbxela commented Nov 11, 2020

@olivermue thanks a lot! It solved my problem too.

I have an ASP.NET Core Project targeting 2.2 and I got the error from the issue after installing .Net 5.0 yesterday.
I also have tried to restart windows before adding the variable DOTNET_HOST_PATH, and it did not help.

Funny is, that the project was successfully built using dotnet CLI without the DOTNET_HOST_PATH env. variable.

@celoko-cintra
Copy link
Author

I added DOTNET_HOST_PATH as dotnet, and it also solved after restarting VS twice.
Thanks to everyone!

@Elinareso
Copy link

I faced the same issue after update VS to the latest version 16.8 and after apply the @olivermue solution I was able to compile and run the web app, however any of the javascript and styles files are loaded correctly now :(.

@celoko-cintra
Copy link
Author

celoko-cintra commented Nov 11, 2020

I faced the same issue after update VS to the latest version 16.8 and after apply the @olivermue solution I was able to compile and run the web app, however any of the javascript and styles files are loaded correctly now :(.

It´s a problem on Razor to recognize new env variable.
Just try to restart your computer. I had the same problem and after restarting all came back!

@fsari
Copy link

fsari commented Nov 11, 2020

Added the following environment variable to my user environment to make it build again:
DOTNET_HOST_PATH
%ProgramFiles%\dotnet\dotnet.exe

It was worked for me

@fsari
Copy link

fsari commented Nov 11, 2020

I faced the same issue after update VS to the latest version 16.8 and after apply the @olivermue solution I was able to compile and run the web app, however any of the javascript and styles files are loaded correctly now :(.

It´s a problem on Razor to recognize new env variable.
Just try to restart your computer. I had the same problem and after restarting all came back!

It is not working. solution is environment editing

@faridprogrammer
Copy link

I faced the same issue after update VS to the latest version 16.8 and after apply the @olivermue solution I was able to compile and run the web app, however any of the javascript and styles files are loaded correctly now :(.
Hi
Did you find the solution? I am having the same problem now.

@augustoproiete
Copy link

I got the same issue and had to manually set the DOTNET_HOST_PATH
environment variable as described by @olivermue above

setx DOTNET_HOST_PATH "%ProgramFiles%\dotnet\dotnet.exe"

@faridprogrammer
Copy link

I got the same issue and had to manually set the DOTNET_HOST_PATH
environment variable as described by @olivermue above

setx DOTNET_HOST_PATH "%ProgramFiles%\dotnet\dotnet.exe"

Thanks.
Setting it normally on windows settings didn't work for me. But this way solved the problem

@dathway
Copy link

dathway commented Nov 11, 2020

Getting the same error in Visual Studio for Mac 8.8

Is there a known workaround for this? I can't figure out how to set the environment variable on mac...

@faridprogrammer
Copy link

faridprogrammer commented Nov 11, 2020

Getting the same error in Visual Studio for Mac 8.8

Is there a known workaround for this? I can't figure out how to set the environment variable on mac...

@augustoproiete reply was helpful for me.

setx DOTNET_HOST_PATH "%ProgramFiles%\dotnet\dotnet.exe"

@dathway
Copy link

dathway commented Nov 11, 2020

Getting the same error in Visual Studio for Mac 8.8
Is there a known workaround for this? I can't figure out how to set the environment variable on mac...

@augustoproiete reply was helpful for me.

setx DOTNET_HOST_PATH "%ProgramFiles%\dotnet\dotnet.exe"

I'm on Mac, not windows.

@Silvenga
Copy link

Not sure this issue should be under the SDK project. Is there an open issue on the developer community?

@augustoproiete
Copy link

@dathway I'd guess that on OSX it would look something similar to

export DOTNET_HOST_PATH=/usr/local/share/dotnet

You should be able to run which dotnet to find dotnet on the path.

@dathway
Copy link

dathway commented Nov 12, 2020

@dathway I'd guess that on OSX it would look something similar to

export DOTNET_HOST_PATH=/usr/local/share/dotnet

You should be able to run which dotnet to find dotnet on the path.

Thank you, but I've tried this and it does not work. Still stuck. All of my projects which target dotnet core 3.1 are unaffected, just the ones at 2.2

@parrywh
Copy link

parrywh commented Nov 12, 2020

@dathway I'd guess that on OSX it would look something similar to

export DOTNET_HOST_PATH=/usr/local/share/dotnet

You should be able to run which dotnet to find dotnet on the path.

Thank you, but I've tried this and it does not work. Still stuck. All of my projects which target dotnet core 3.1 are unaffected, just the ones at 2.2

same here, using Mac and exporting the DOTNET_HOST_PATH doesn't seem to resolve the build issue

@Chengxiaozhi
Copy link

@dathway I'd guess that on OSX it would look something similar to

export DOTNET_HOST_PATH=/usr/local/share/dotnet

You should be able to run which dotnet to find dotnet on the path.

Thank you, but I've tried this and it does not work. Still stuck. All of my projects which target dotnet core 3.1 are unaffected, just the ones at 2.2

same here, using Mac and exporting the DOTNET_HOST_PATH doesn't seem to resolve the build issue

Using vs mac fails, but using vs code is normal.

@ghost
Copy link

ghost commented Nov 12, 2020

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!

@Shane32
Copy link

Shane32 commented Nov 12, 2020

I'm having the same problem

@brunokenj
Copy link

brunokenj commented Nov 12, 2020

Anyone found a solution for osx (10.15.6) / vs 16.8.0 (8.8 for mac) / aspnetcore 2.2 project ?

Same problem after deleted NuGetFallbackFolder folder, added export DOTNET_HOST_PATH in .profile or .bash_profile, .zshrc, .zprofile, seen the variable in 'env', added in run 'custom configuration'.

Edit: dotnet run in terminal works fine. vs code attaching process for debug also works. visual studio 8.8 didn't work.

Edit 2: when I changed build proccess to verbose mode in VS 8.8, the only variable with dotnet are DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR = /usr/local/share/dotnet.

Edit 3: Running in terminal works fine: dotnet msbuild /p:MSBuildExtensionPath='/Users/xxx/Library/Caches/VisualStudio/8.0/MSBuild/8639_1/MonoDevelop.MSBuildBuilder.exe' /p:Configuration=Debug /v:diag

Tried to force this variable in .csproj file but no success running in VS 8.8 in OSX, the variable was never there.

Edit 4: Finally.... now I was able to run in VS 8.8 in OSX.

Add after < Project> in .csproj

< PropertyGroup>
< DOTNET_HOST_PATH Condition=" '$(DOTNET_HOST_PATH)' == '/usr/local/share/dotnet' ">
</ DOTNET_HOST_PATH>
< /PropertyGroup>
< Target Name="BugVSBuild">
< Message Text="Building using the tools at $(DOTNET_HOST_PATH)..." />
< /Target>

Edit 5: I had delete the above configuration because after closing VS, I got the same error....

The final solution for me: open the terminal, go to the project folder and run: dotnet msbuild /p:MSBuildExtensionPath='/Users/brunokenj/Library/Caches/VisualStudio/8.0/MSBuild/8639_1/MonoDevelop.MSBuildBuilder.exe' /p:Configuration=Debug /v:diag

After that command, seems msbuild in vs can read the DOTNET_HOST_PATH variable (from .profile file?) and build the web project.

@jonalexjm
Copy link

Added the following environment variable to my user environment to make it build again:
DOTNET_HOST_PATH
%ProgramFiles%\dotnet\dotnet.exe

It was worked for me

It Was worked too me! Thanks

@jcdekoning
Copy link

Any suggestion how to solve this for a solution that both contains a Microsoft.NET.Sdk.Razor project and F# class libraries. Because setting DOTNET_HOST_PATH environment variable interfere with running the F# compiler as discussed here dotnet/fsharp#10447

@dgenezini
Copy link

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!

Thanks.

If someone is using a build agent or building in a service, the command must have a /M to make it system wide and not only local:

setx DOTNET_HOST_PATH "%ProgramFiles%\dotnet\dotnet.exe /M

@terrier-tom
Copy link

terrier-tom commented Nov 13, 2020

I added a comment to the thread on the VS developer community site (link below) with an update on how I got things to work for me. Essentially I got rid of a nuget package in my local cache and things worked without the DOTNET_HOST_PATH system environment variable. The only "gotcha" was if I did a rebuild all on my solution, the package was re-added to my local nuget cache and the problem returned. Deleting the cached package (again) did (again) fix things -- at least for me.

https://developercommunity2.visualstudio.com/t/razortaghelper-task-failed-unexpectedly/1249786?from=email&viewtype=all#T-ND1255738

Updating the project file as follows seems to have resolved things for me. DOTNET_HOST_PATH environment variable not needed with this change:

<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0"> <ExcludeAssets>Build</ExcludeAssets> </PackageReference>

@ianfoster99
Copy link

ianfoster99 commented Nov 25, 2020

Adding Microsoft.NET.Sdk.Razor to my Web project worked for me

@SheepRock
Copy link

For me, a global.json on the solution folder level with the 2.2 SDK (dotnet --list-sdks) like MSB4018 The RazorTagHelper task failed unexpectedly - after VS upgrade suggested was a viable workaround:

{
  "sdk": {
    "version": "2.2.207"
  }
}

This is the most simple solution. Worked for me without restarting the VS or the PC.

@Syedkumailabbaszaidi
Copy link

Adding Microsoft.NET.Sdk.Razor to my Web project worked for me

This worked for me on Visual Studio For Mac.

@nqdung16
Copy link

Adding Microsoft.NET.Sdk.Razor to my Web project worked for me

I'm new here so I don't know where to add that line. Please give me more specific info

@nathan-globaloffice
Copy link

@nqdung16 Microsoft.NET.Sdk.Razor is a nuget package. You'll need to add it to your web project using either NuGet Pacakage Manager (built into VS) or, if your using the new project reference style, by editing the .csproj file.

@nqdung16
Copy link

Microsoft.NET.Sdk.Razor

I got it. Thanks

@Fabian651
Copy link

Fabian651 commented Nov 30, 2020

On mac, I fixed it with running the project from bash dotnet watch run --urls http://0.0.0.0:5001

@ryanmz1
Copy link

ryanmz1 commented Dec 1, 2020

Adding this line in project file works or install razor package:
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0"></PackageReference>

reference:

https://stackoverflow.com/questions/64827539/msb4018the-razorgenerate-task-failed-unexpectedly

@pranavkm pranavkm transferred this issue from dotnet/sdk Dec 2, 2020
@pranavkm pranavkm added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Dec 3, 2020
@pranavkm pranavkm self-assigned this Dec 3, 2020
@hungxp
Copy link

hungxp commented Dec 3, 2020

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!

Thanks!

@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Dec 3, 2020
@mkArtakMSFT mkArtakMSFT added this to the 5.0.2 milestone Dec 3, 2020
@psnehi
Copy link

psnehi commented Dec 4, 2020

Added the following environment variable to my user environment to make it build again:
DOTNET_HOST_PATH
%ProgramFiles%\dotnet\dotnet.exe

My issue resolved. Thanks.

@ship-store
Copy link

Adding this line in project file works or install razor package:
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0"></PackageReference>

reference:

https://stackoverflow.com/questions/64827539/msb4018the-razorgenerate-task-failed-unexpectedly

Worked like a Charm !!

@mkArtakMSFT mkArtakMSFT added Servicing-consider Shiproom approval is required for the issue Working labels Dec 7, 2020
@ghost ghost added Done This issue has been fixed and removed Working labels Dec 9, 2020
@pranavkm
Copy link
Contributor

pranavkm commented Dec 9, 2020

Thank you for the issue report. We inadvertently broke support for ASP.NET Core 2.2 as part of the 5.0 SDK which is why you're seeing this error. We're addressing this in 5.0.2 which is set to be released early next month. In the meanwhile there are a few workaround:

<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0" />
  • You could consider setting an environment variable for DOTNET_HOST_PATH globally. The value is likely %ProgramFiles%\dotnet\dotnet.exe

I would like to add that .NET Core 2.2 has been out of support for some time now and is no longer receiving any updates (including security fixes). You should consider migrating to a supported releases (2.1, 3.1 or 5.0) to continue to be supported.

@uandersonmbc
Copy link

This was resolved in macOS Catalina. Version 10.15.7

For those who have not yet managed to define the environment variable, enter this site that will help a lot. To resolve the DOTNET_HOST_PATH is not set problem. After hours and hours looking for solutions, I found this site.

http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-launchd-plist/

@oshinyil

This comment has been minimized.

@ankitmori14

This comment has been minimized.

@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed Servicing-consider Shiproom approval is required for the issue
Projects
None yet
Development

No branches or pull requests