aspnet/Razor

Build fails when running from VSTS Build Agent Test Task

jag43 opened this issue · 4 comments

jag43 commented

I was told to create a new issue from #2553 .

I am getting this error when running the VSTS test task as part of a build pipeline for an AspNetCore Mvc web app running on dotnet core.

C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.razor.design\2.1.2\build\netstandard2.0\Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets(69,5): error MSB4062: The "Microsoft.AspNetCore.Razor.Tasks.RazorTagHelper" task could not be loaded from the assembly C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.razor.design\2.1.2\build\netstandard2.0\..\..\\tasks\netstandard2.0\Microsoft.AspNetCore.Razor.Tasks.dll. Assembly with same name is already loaded Confirm that the <UsingTask> 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. [D:\a\1\s\WebApps\WebApps.TeleM\WebApps.TeleM.csproj]

I'm not sure if that's because of how our project is set up or if I've misunderstood something.
AspNetCore.Mvc is referenced from 3 places (all 2.1.3):

  • WebHelper project (via a different nuget package which has a dependency on AspNetCore.Mvc),
  • Razor Class Library project (this already references our WebHelper project, but the explicit reference is needed for the Razor Class Library to function properly) and
  • Our WebApp project references the Razor Class Library and AspNetCore.App (version now removed as recommended)

I think I have tried everything suggested in the other thread but I'm still getting the error.

  • Remove the version from the Microsoft.AspNetCore.App package reference

I removed the version from all our web app projects (the only place the App package is referenced)

  • Add an explicit reference to the latest version of the Microsoft.AspNetCore.Razor.Design package to make sure you're getting the latest Razor MSBuild tasks.

I added this reference to all our WebApp projects and all our unit test projects, all projects with cshtml files, is that right?

  • Update your .NET Core SDK on your dev machine

The issue doesn't occur on our dev machines, but on the VSTS build agent. It looks like the most recent version installed on the agent is 2.1.402 (the agent is provided by VSTS)

  • For CI environments we also suggest passing the /nodeReuse:false flag

I have added this to the VSTS test task, so the full command is now dotnet test --logger:trx --configuration $(BuildConfiguration) /nodeReuse:false

Is there anything I've missed or is there another problem here?

Thanks for contacting us, @jag43.
@pranavkm, can you please look into this? Thanks!

@jag43 dotnet test does not pass parameters to the underlying dotnet build call which is where the nodereuse setting would make a difference. Could you try this:

dotnet build /nodeReuse:false --configuration $(BuildConfiguration)
dotnet test --no-build --no-restore --logger:trx --configuration $(BuildConfiguration)

Perhaps that might help.

jag43 commented

@pranavkm I've made these changes you suggested, and also added <UseRazorBuildServer>false</UseRazorBuildServer> to all the projects with cshtml files (suggestion from the previous thread) and one or both of these seems to have fixed our builds. Thanks for your help.

Out of curiosity, do you know if the UseRazorBuildServer could have any side-effects? The docs say

Uses a persistent build server process to offload code generation work.

But I'm not too sure what that really means.

It's a performance optimization - Razor uses it to cache compilation artifacts between rebuilds. It typically makes sense on your development boxes (compiling from scratch is expensive), so if you're able to throw that behind a flag e.g `false that would be better. But in general there should be no side effects to turning it off.