Using MsBuild project files to copy files without VS.Net "Helping" the process

time to read 6 min | 1123 words

I posted before that adding the ability to copy files after a build was not as straight forward as it should, mainly because VS.Net decides to take active part in this and resolve the paths manually.

Here is how I ended up solving the issue:

<Target Name="AfterBuild">

        <CreateItem Include="$(MSBuildProjectDirectory)\..\Configuration\**\*.config">

              <Output TaskParameter="Include"

                          ItemName="ConfigurationFiles" />

        </CreateItem>

        <RemoveDir Directories="$(MSBuildProjectDirectory)\bin\$(Configuration)\Configuration" />

        <MakeDir Directories="$(MSBuildProjectDirectory)\bin\$(Configuration)\Configuration" />

        <Copy SourceFiles="@(ConfigurationFiles)"

                  DestinationFolder="$(MSBuildProjectDirectory)\bin\$(Configuration)\Configuration\%(RecursiveDir)" />

  </Target>

This force runtime evaluation, and thus saving it from VS.Net clutches. I got the script from Doug, who uses it to copy files that are created on the fly.