title: How do I get an msbuild task to do config transforms on a collection of files?
body: <p>I am trying to transform all of the web.config files in a project I have, here's a my tree structure:</p>
  
  <ul>
  <li>Transform.bat</li>
  <li>Transforms
  <ul>
  <li>ConfigTransform.proj</li>
  <li>Web.Transform.config</li>
  </ul></li>
  <li>Website
  <ul>
  <li>web.config</li>
  <li>Views
  <ul>
  <li>web.config</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>There's more web.config files, but the idea is that this will find all of them and apply the same config transform on them. </p>
  
  <p>I've taken a few hints from <a href="http://sedodream.com/2010/11/18/XDTWebconfigTransformsInNonwebProjects.aspx">a blog post I found</a> but I get stuck in the last step, the actual transformation. Also there's a bit of a rough part in the middle that I don't really like (I don't quite understand what I'm doing and I'm obviously doing it wrong). Here's where I am so far:</p>
  
  <pre><code>&lt;Project ToolsVersion="4.0" DefaultTargets="Transform" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
      &lt;UsingTask TaskName="TransformXml" AssemblyFile="Tools\Microsoft.Web.Publishing.Tasks.dll"/&gt;
  
      &lt;PropertyGroup&gt;
          &lt;SitePath&gt;..\..\Website&lt;/SitePath&gt;
          &lt;WebConfigTransformInputFile&gt;$(SitePath)\Web.config&lt;/WebConfigTransformInputFile&gt;
          &lt;WebConfigTransformFile&gt;Web.Transform.config&lt;/WebConfigTransformFile&gt;
          &lt;OutDir&gt;..\N\N\&lt;/OutDir&gt;
  
      &lt;/PropertyGroup&gt;
  
      &lt;ItemGroup&gt;
          &lt;_FilesToTransform Include="$(SitePath)\**\web.config"/&gt;
      &lt;/ItemGroup&gt;
  
      &lt;Target Name="Transform"&gt;
  
      &lt;MakeDir Directories="@(_FilesToTransform-&gt;'$(OutDir)%(RelativeDir)')" /&gt;
  
      &lt;TransformXml Source="@(_FilesToTransform-&gt;'$(OutDir)%(RelativeDir)%(Filename)%(Extension)')"
                    Transform="$(WebConfigTransformFile)"
                    Destination="@(_FilesToTransform-&gt;'$(OutDir)%(RelativeDir)%(Filename)%(Extension)')" /&gt;
      &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>My Transform.bat looks like this: </p>
  
  <pre><code>%systemroot%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe %CD%\Transforms\ConfigTransform.proj
  </code></pre>
  
  <p>So when I call the batch, the appropriate directories get created. However, as you can see I've had to be a little creative with the OutDir, making it ..\N\N. For some reason, if I don't do this the OutDir path will be exactly the same as the input directory. So I obviously need to change something in MakeDir but I'm not sure what.</p>
  
  <p>The real problem comes when it starts to do the transforms. I've tried to keep the TransformXml Source parameter like this or like so:</p>
  
  <pre><code>@(_FilesToTransformNotAppConfig-&gt;'%(FullPath)')
  </code></pre>
  
  <p>The latter gives me an error "Could not open Source file: The given path's format is not supported." and the former gives me this output:</p>
  
  <pre><code>Build started 30-4-2012 14:02:48.
  Project "D:\Dev\transform\DoTransforms\Transforms\ConfigTransform.proj" on node 1 (default targets).
  Transform:
    Creating directory "..\N\N\..\..\Website\Views\".
    Transforming Source File: ..\N\N\..\..\Website\Views\Web.config;..\N\N\..\..\Website\Web.config
  D:\Dev\transform\DoTransforms\Transforms\ConfigTransform.proj(32,2): error : Could not open Source file: Could not find a part of the path 'D:\Dev\transform\DoTransforms\Website\Views\Web.config;\Website\Web.config'.
    Transformation failed
  Done Building Project "D:\Dev\transform\DoTransforms\Transforms\ConfigTransform.proj" (default targets) -- FAILED.
  
  Build FAILED.
  </code></pre>
  
  <p>To summarize my questions:</p>
  
  <ol>
  <li>How do I avoid the path issue for the OutDir? I've fiddled with multiple paths but I can't get it right.</li>
  <li>How do I get the TransformXml task to accept multiple files in the Source attribute?</li>
  </ol>