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

9

39

Hello I have build server with TeamCity. My project is Sitecore Web Application. I am using TDS (HedgehogDevelopment). I have setup build settings in TeamCity with MS build and it looks like working when TDS project is disabled in build configuration manager. But then it enebled I am getting net error

C:\Program Files (x86)\MSBuild\HedgehogDevelopment\SitecoreProject\v9.0\HedgehogDevelopment.SitecoreProject.targets(310, 5): error MSB4036: The "TransformXml" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework64\v3.5" directory. Project NetKey.TDSMaster\MyProject.TDSMaster.scproj failed. Project Website\MyProject.sln failed

The help in error description is not a case for me. I don't have VS 2012 on build machine. I have installed Microsoft Visual Studio 2012 Shell for support my web project. How to resolve it ? Thanks.

Rapport answered 20/5, 2013 at 9:43 Comment(0)
B
25

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

Barcelona answered 20/5, 2013 at 10:34 Comment(5)
I have installed this and a lot of other tools from Web Platform Installer 4.5 but it dos't work.Bern
By default the TransformXML task is added here: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v{VisualStudioVersion}\Web\Microsoft.Web.Publishing.targets. Installing Visual Studio properly (meaning Visual Studio Pro or better) should fix the issue. Or you can try to copy/paste the msbuild folder from a machine that does have Visual Studio installed which may work if the tasks do not have a dependency on any other library that ships with Visual Studio.Barcelona
Confirmed that copying the entire C:\Program Files (x86)\MSBuild folder to the TeamCity build server will allow running the TransformXML task. I tried copying over just the files that seemed relevant to the TransformXML task, but still got the error (until I copied the entire MSBuild folder)Selinski
Confirmed that installing VS2013 does not fix the issue.Decomposed
Confirmed that copying the entire C:\Program Files (x86)\MSBuild folder to the build server will allow running the TransformXML task. My dev machine had Visual Studio 2013 Update 2 with Update 4 patched in and MS Web Developer Tools installed. Whereas, my build machine had VS 2013 Update3 with Update 4 patched in without MS Web Developer Tools installed. So, copying the MSBuild folder from my development machine to the build machine worked and may have copied over additional files that were present because on my development machine because of the MS Web Developer Tools installation.Father
D
20

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')" />
Decomposed answered 26/11, 2014 at 18:20 Comment(1)
What's interesting is I used to not to have to use the XMLTransform task, it automatically did it. And then one day it just stopped. Any ideas why?Glooming
B
19

Try this:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
Brockbrocken answered 13/3, 2014 at 16:42 Comment(0)
C
11

You you have a lots of Visual Studio version, then try this

VS2015

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

VS 2017

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

VS 2019

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

<Target Name="TransformConfig">
    <MakeDir Directories="$(TargetDir)" Condition="  Exists('$(TargetPath)') == False " />
    <TransformXml Source="app.config"
        Transform="app.$(Configuration).config"
        Destination="$(TargetPath).config" />
</Target>

Concavoconcave answered 30/9, 2019 at 11:46 Comment(1)
In addition Since Visual Studio 2022 is out now, just change the version from v1x.0 to v17.0Stilliform
H
3

Solutions provided seem to work for using VS as an IDE, but if you use DotnetCore via CLI or on a unix based system this does not work.

I found that the following seem to work

  <PropertyGroup>
    <XmlTransformDllPath Condition="'$(XmlTransformDllPath)' == '' AND '$(MSBuildRuntimeType)' == 'core'">$(MSBuildSDKsPath)/Microsoft.NET.Sdk.Publish/tools/net5.0/Microsoft.NET.Sdk.Publish.Tasks.dll</XmlTransformDllPath>
    <XmlTransformDllPath Condition="'$(XmlTransformDllPath)' == '' AND '$(MSBuildRuntimeType)' != 'core'">$(MSBuildSDKsPath)/Microsoft.NET.Sdk.Publish/tools/net472/Microsoft.NET.Sdk.Publish.Tasks.dll</XmlTransformDllPath>
    <XmlTransformDllPath Condition="!Exists($(XmlTransformDllPath))">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll</XmlTransformDllPath>
  </PropertyGroup>
  <UsingTask TaskName="TransformXml" AssemblyFile="$(XmlTransformDllPath)" />

This solution takes into account netcore, full .net

For some reason MSBuildSDKsPath and MSBuildExtensionsPath32 are different on windows when using CLI vs VS2019

CLI: MSBuildSDKsPath = C:\Program Files\dotnet\sdk\5.0.103\Sdks MSBuildExtensionsPath32 = C:\Program Files\dotnet\sdk\5.0.103

Vs2019 MSBuildSDKsPath = C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Sdks MSBuildExtensionsPath32 = C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild

Which on my Mac returns /usr/local/share/dotnet/sdk/5.0.201

Only problem I see is with the tools/net5.0 part of the name which changes ever release

Hertz answered 22/3, 2021 at 14:58 Comment(2)
Opened github.com/dotnet/sdk/issues/16469 regarding my comments about TFMHieratic
As Max mentions, the tools/net5.0 changes with every release - which I noticed on my Azure Build Agents that stopped building my projects. Use this instead: tools/$(WasmNativeWorkload)Asinine
V
1

In Visual Studio 2017 by default most(or all?) components are not installed, but you can add what's required (i.e. Asp.Net and web development) as described in https://learn.microsoft.com/en-us/visualstudio/install/modify-visual-studio.

On my machine the installer located at "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe"

Vidette answered 13/3, 2017 at 6:35 Comment(5)
I do have "ASP.NET and web development" selected, but I don't have the "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web" folder. What am I missing?Emplacement
I found the following NuGet that does the job: github.com/pdonald/nuget-webtargetsEmplacement
@Fabrice, v14.0 is for Visual Studio 2015, 2017 components are located somewhere else ( probably in v15.0 folder)Vidette
They are not in the v15.0 folder. It seems other components than "ASP.NET and web development" must be installed. strangely, according to Visual Studio, they are related to Windows development.Emplacement
@MichaelFreidgeim I just managed to fix this problem after installing what felt like everything. The solution was as follows 1. Install VS 2017 (community for me) onto the build server 2. Install VS build tools 2017 3. Modify build tools and select Web development build tools.Peel
P
1

I had the same problem after downgrading TypeScript tools from 2.4.10 to 2.3.3 in VS2015.

Solution:

I remove this from Microsoft.TypeScript.targets file

    <FormatLocalizedString Condition="'$(TypeScriptVersionCheckResult)' == 'NoneSpecified'"
  Culture="$(PreferredUILang)" 
  Name="TypeScriptNoVersionWarning" 
  Arguments="$(LastKnownTypeScriptVersion)">
  <Output TaskParameter="String" PropertyName="TypeScriptNoVersionWarning" />
</FormatLocalizedString>

<FormatLocalizedString Condition="'$(TypeScriptVersionCheckResult)' == 'Downgrade' OR '$(TypeScriptVersionCheckResult)' == 'Upgrade'"
  Culture="$(PreferredUILang)" 
  Name="TypeScriptVersionMismatchWarning" 
  Arguments="$(TypeScriptToolsVersion);$(LastKnownTypeScriptVersion)">
  <Output TaskParameter="String" PropertyName="TypeScriptVersionMismatchWarning" />
</FormatLocalizedString>
Perspicacity answered 12/7, 2017 at 8:56 Comment(1)
I 've got this error after uninstalling VS 2019, and using VS 2022 in project asp.net web api core 6.0. Deleting parts mentioned above helped me.Aphasia
R
0

Just had this problem while trying to build my project using msbuild with the command line. The command is pretty big and I failed to notice the argument /p:VisualStudioVersion="14.0" was wrong, which resulted in a wrong path to Microsoft.Web.Publishing.targets. Since I'm using Visual Studio 2019 it should have been /p:VisualStudioVersion="16.0" or simply removed.

For anyone with the same problem, double check your msbuild parameters, and check if any .csproj property depends on your visual studio version.

I knew C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets should be imported, but my .csproj had

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

and still TransformXml was not found. I tried logging VsToolsPath with

<Project InitialTargets="CopyInitialConfig">
    ...
    <Target Name="MyTarget">
        <Message Importance="High" Text="VS Tools is at $(VSToolsPath)" />
    </Target>
    ...

Which on build logged

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets
Rhatany answered 21/9, 2020 at 10:51 Comment(0)
T
0

I don't have visual studio in my server. I only installed msbuild.For resolving my problem, I found that I don't have folder "Web in "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web. So I copied this folder from my system installed visual studio and pasted on my server and It resolved my problem.

Tude answered 15/11, 2021 at 10:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.