Dotnet Core 2.0 build fails with Error MSB4062: The “GetDotNetHost” task could not be loaded from the assembly

We were recently observing this issue with one of the new source code repositories for a solution that was written in .NET Core 2.0. The source code was coded using Visual Studio and it was working fine on the developers machine. However, when building it using dotnet core publish task, it kept failing with below error:

T12:47:54.2728059Z C:\Windows\ServiceProfiles\NetworkService.nuget\packages\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.4\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets(45,5): error MSB4062: The “GetDotNetHost” task could not be loaded from the assembly C:\Windows\ServiceProfiles\NetworkService.nuget\packages\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.4\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tasks.dll. Assembly with same name is already loaded Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask

2018-08-07T12:47:56.5392586Z C:\Windows\ServiceProfiles\NetworkService.nuget\packages\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.4\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets(45,5): error MSB4062: The “GetDotNetHost” task could not be loaded from the assembly C:\Windows\ServiceProfiles\NetworkService.nuget\packages\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.4\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tasks.dll. Assembly with same name is already loaded Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask

It did not matter’ed which pool we used to run this whether VS2017 or private pools in VSTS, it kept failing with same error.

After a little more checking into source code, we figured out that we were using different versions of Nuget package for Microsoft.AspNetCore.All in different projects. One had 2.0.5, other had 2.0.6 whilst one other had 2.0.8. After we updated all to use the same version and checked-in the new version of the source code, we were able to build fine. We tried using both 2.0.6 and 2.0.8 and it worked fine. So apparently all it need is to use the same version.

 

One thought on “Dotnet Core 2.0 build fails with Error MSB4062: The “GetDotNetHost” task could not be loaded from the assembly

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s