11

I have an imported MSBuild project (appconfig.transformation.targets) that defines some tasks and puts them in the BuildDependsOn property. I've placed this file in the top level folder for a solution (Projects\LibrariesSolution\appconfig.transformation.targets):

<PropertyGroup>
  <BuildDependsOn>
    TransformWebConfig;
    OverrideAppConfigWithTargetPath;
    $(BuildDependsOn);
    CopyTransformedConfig
  </BuildDependsOn>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />

I import this project in each csproj file inside the solution in subfolders. So Projects\LibrariesSolution\Project1\Project1.csproj has something like this:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
  <Import Project="..\appconfig.transformation.targets" />
  ... the rest of the csproj stuff ...

I launch the build like so:

cd LibrariesSolution
c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /t:Clean /p:Configuration=Release Project1\Project1.csproj
c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /t:Build /p:Configuration=Release Project1\Project1.csproj

But the targets listed in BuildDependsOn do not appear to be called. Of course the output is way too verbose to show here, but "TransformWebConfig" does not appear anywhere in the output. No errors are shown. What could be wrong? What should I do to troubleshoot the process further?

Jake Stevenson
  • 3,009
  • 6
  • 35
  • 40

1 Answers1

17

You have an import order problem. You are importing your file (appconfig.transformation.targets) which defines the property BuildDependsOn. Later in the project file, the Microsoft targets are imported, which redefine BuildDependsOn and wipe out your changes because their definition does not include any existing value in BuildDependsOn.

BuildDependsOn is defined in Microsoft.Common.targets which is imported by Microsoft.CSharp.targets for a C# project. Your import should go after the import of Microsoft.CSharp.targets.

Brian Walker
  • 8,658
  • 2
  • 33
  • 35