32
votes

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.

8

8 Answers

25
votes

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

19
votes

Try this:

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

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')" />
6
votes

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>

1
votes

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://docs.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"

1
votes

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

0
votes

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>
0
votes

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