Home > Net >  TeamCity Msbuild: The "TransformXml" task could not be loaded
TeamCity Msbuild: The "TransformXml" task could not be loaded

Time:09-15

I have a project that I'm trying to build under .NET 6 using TeamCity. The build always fails with an error message:

error MSB4062: The "TransformXml" task could not be loaded from the assembly ...

I found this thread and decided to install the MSBuild.Microsoft.VisualStudio.Web.targets Nuget package. Now my .csproj file looks like this:

    <Import Project="$(NuGetPackageRoot)MSBuild.Microsoft.VisualStudio.Web.targets\14.0.0.3\tools\VSToolsPath\Web\Microsoft.Web.Publishing.targets" Condition="true" />
    <UsingTask TaskName="TransformXml" AssemblyFile="$(NuGetPackageRoot)MSBuild.Microsoft.VisualStudio.Web.targets\14.0.0.3\tools\VSToolsPath\Web\Microsoft.Web.Publishing.Tasks.dll" />

    <Target Name="ApplyConfigurationConfigFile" AfterTargets="PrepareForBuild" Condition="Exists('App.$(EnvironmentName).config')">
        <ItemGroup>
            <AppConfigWithTargetPath Remove="App.config" />
            <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
                <TargetPath>$(TargetFileName).config</TargetPath>
            </AppConfigWithTargetPath>
        </ItemGroup>
        <TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.$(EnvironmentName).config" />
    </Target>

I've tried like a dozen different ways to do this, but it always comes back to the same error message:

error MSB4062: The "TransformXml" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\6.0.108\Microsoft\VisualStudio\v17.0\Web\Microsoft.Web.Publishing.Tasks.dll. Could not load file or assembly 'C:\Program Files\dotnet\sdk\6.0.108\Microsoft\VisualStudio\v17.0\Web\Microsoft.Web.Publishing.Tasks.dll'. The system cannot find the path specified. 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.

I really don't understand this because surely $(NuGetPackageRoot) should be pointing to some other folder?

I've actually even tried with the SlowCheetah Nuget package and it was failing with the same error message (apparently it calls the original TransformXml task internally).

Anyone know how to fix this?

CodePudding user response:

The trick to make this work was <Project SDK="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">.

Adding Microsoft.NET.Sdk.Publish makes the <TransformXml> task available. No need to use a Nuget package or anything.

  • Related