Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransformXml task fails via msbuild on linux using mono

Tags:

c#

mono

msbuild

After following the steps in this answer, when attempting to build a project through mono (Using msbuild), I get the following error:

(AfterCompile target) -> project.csproj(469,5): error MSB4062: The "TransformXml" task could not be loaded from the assembly /usr/lib/mono/xbuild/Microsoft/VisualStudio/v15.0/Web/Microsoft.Web.Publishing.Tasks.dll. 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 appears as if Microsoft.Web.Publishing.Tasks.dll is unavailable.

like image 254
ugh StackExchange Avatar asked Jul 14 '17 08:07

ugh StackExchange


People also ask

Where is the transformxml task located?

The task is correctly declared with in the project file, or in the *.tasks files located in the "C:\Program Files (x86)\MSBuild\14.0\bin" directory. 1>Where is TransformXml is located?

What is xbuild in mono?

xbuild is Mono’s implementation of msbuild and it allows projects that have an msbuild file to be compiled natively on Linux. xbuild has been part of the standard Mono distribution for some time now, but it is not 100% complete yet. xbuild supports C# and VB.NET projects out of the box.

Why can’t I do an XML transformation in Visual Studio?

The main problem with an XML transformation is that it happens on the “ web publish ” step only, and you can’t have it setup for the build (via Visual Studio IDE, that is).

How do I create a config transform file in Visual Studio?

If your project doesn’t have the transformation files yet (upgraded solution) or you added new build configurations, open your project in Visual Studio, right-click the existing Web.config file, and select Add config transform. This will create config files for existing solution configurations (e.g. web.Debug.config and web.Release.config ).


1 Answers

On linux via mono, this file doesn't exist. To solve this issue, follow these steps:

  1. Install the nuget package MSBuild.Microsoft.VisualStudio.Web.targets
  2. Right click your project, and click "Unload Project"
  3. Right click your (now unloaded) project, and click "Edit MyProjectName.csproj"
  4. Replace this line:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />

With your updated nuget Microsoft.Web.Publishing.Tasks.dll location (Update version name in MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0.3 as necessary):

<UsingTask TaskName="TransformXml" AssemblyFile="..\packages\MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0.3\tools\VSToolsPath\Web\Microsoft.Web.Publishing.Tasks.dll" />
  1. Reload your project, and voila, working build on linux!
like image 121
ugh StackExchange Avatar answered Nov 06 '22 23:11

ugh StackExchange