I have a problem running a gulp task for transforming my config files. It reports following error:
error MSB4062: The "TransformXml" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsof t.Web.Publishing.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confi rm 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.
What the task does:
- It creates a
_msbuild.proj
file with config file to be transformed. The file looks like this (obviously Source, Transform and Destination are filled in with real data):
<Project ToolsVersion="4.0" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<Target Name="Transform">
<TransformXml Source="" Transform="" Destination=""/>
</Target>
</Project>
- The it runs this file against msbuild:
C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\msbuild.exe .\_msbuild.proj /t:Transform
I have already seen this answer which suggests it is a nuget package and might be corrupted. I don't think that's the case since everyone else in my project does not have this problem. Also I do have the problematic dll - Microsoft.Build.Utilities.Core
however in a higher version (16.4.0) installed in various places along with dotnet and VS installation.
The only difference I see is that I am using VS 2019 and have the Microsoft.Web.Publishing.Tasks.dll
(a library which contains TransformXml taks and depends on missing library) in different location on disk than it is in the gulp transform module - I have it in C:\Program Files (x86)\Microsoft Visual Studio
while others have it in C:\Program Files (x86)\MSBuild
I am stuck on this problem for almost a day now and cannot move a bit.
I think the issue is that you used the
msbuild.exe
of Framework version rather than msbuild of VS2019.And
C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\msbuild.exe .\_msbuild.proj /t:Transform
means that you use the msbuild of Framework.To explain it more detailed:
MSBuild of VS2019 integrates with a variety of vs environment parameters, is directly related to your various operations in vs, and the framework's msbuild only has the most basic compilation project function which does not have
TransformXml
task.Besides,
Microsoft.Web.Publishing.Tasks.dll
is just a part of msbuild of VS2019 so that it can be recognized by msbuild of VS2019. But this dll is not underC:\Windows\Microsoft.NET\Framework64\v4.0.30319\xxxx
, so use Framework's msbuild cannot get what you want.Solution
As a workaround, you should use MSBuild of VS2019 to correspond to
Microsoft.Web.Publishing.Tasks.dll
which exists in its folder.1) use
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe
to execute_msbuild.proj
.2) Or just use Developer Command Prompt
And I think anyone else also used this msbuild.
Hope it could help you.