The "TransformXml" task was not found (error MSB4036) on TeamCity build

TransformXML comes as part of the ASP.NET Web Publishing tools. As such they usually come with a Visual Studio installation on your build server and require more than just the Shell version of Visual Studio. Installing Visual Studio Express Web Edition might also do the trick.

You could try installing the Web-Deploy package to see whether it's enough, but usually I just install the full version of Visual Studio on a build agent. This is legal under MSDN Subscription licensing.

After some experimenting I can tell that you need to install at least the Visual Studio Web Developer Tools on the build server for these tasks to get installed the official way. I suspect that installing the Visual Studio Express Web Edition would suffice.

enter image description here


Short Answer - Explicitly Import

What I had to do:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets" Condition="!Exists('$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets')" />

Long Answer

When you do File -> New Web Project in VS2013 you get the following inside your *.csproj file:

<PropertyGroup>
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

The $(VisualStudioVersion) always evaluated to 11.0 for me on build machines and on multiple development machines. Even on machines with VS2013, which is 12.0.

Diving into that I found that in the Microsoft.WebApplication.targets from above, it has a line to import the file we really want Microsoft.Web.Publishing.targets only if it exists like so on line 377:

<!--Import publishing target-->
<Import Project="..\Web\Microsoft.Web.Publishing.targets" Condition="Exists('..\Web\Microsoft.Web.Publishing.targets')" />

So to me this is an implicit import of Microsoft.Web.Publishing.targets.

The problem is that if this file doesn't exist, it does nothing and you do not know about it until you get the error when trying to use the TransformXml task.

Installing VS2013 did not install Microsoft.Web.Publishing.targets in the 11.0 directory. It did install it in the 12.0 directory. I'm guessing if I installed VS2012, it would do it.

In any case, I was able to solve it by explicitly importing Microsoft.Web.Publishing.targets from the 12.0 directory if it didn't exist and wasn't implicitly imported by Microsoft.WebApplication.targets like so:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets" Condition="!Exists('$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets')" />

Try this:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />