1

I'm using MSBuild.exe v4.00. I've got a build target in my project file that copies a file named Parameters.MyEnvironment.xml to Parameters.xml. "MyEnvironment" can vary based on when/where MSBuild.exe is called.

This runs, then the Parameters.xml is used by other processes in the MSDeployPublish target.

Finally, I delete the file Parameters.xml because it's just a copy of one of my environment-specific files.

When running as described above, the MSDeployPublish target behaves as though Parameters.xml is not there but does not report an error.

However, if I remove the delete task so Parameters.xml remains after my project build completes , MSDeployPublish sees it and uses it correctly. Strangely, any change to Parameters.MyEnvironment.xml is immediately reflected in the next build process.

To summarize - copying a file (that wasn't previously there) into my project folder that a subsequent target uses does not work. However, if I leave the original file there and overwrite it with a new version of the source, it works reflecting the new content!

This author has identified a locking/open-file issue with MSBuild, have I got the same thing going on here? http://dotnet.dzone.com/articles/using-custom-webconfig-0

Michael12345
  • 2,520
  • 5
  • 23
  • 41

1 Answers1

0

Well, I still haven't gotten to the bottom of why the MSDeployPublish target is tripping over my Copy task. However, I've got a messy workaround that I can live with for now.

I have added these targets to my wdproj file:

<Target Name="BeforeTeamCity">
    <Copy Condition="Exists('$(MSBuildProjectDirectory)\Parameters.$(Configuration).xml')" SourceFiles="$(MSBuildProjectDirectory)\Parameters.$(Configuration).xml" DestinationFiles="$(MSBuildProjectDirectory)\Parameters.xml" />
  </Target>

<Target Name="AfterTeamCity">
  <Delete Files="$(MSBuildProjectDirectory)\Parameters.xml"/>
</Target>

Previously I was trying to fold them into the rest of the build using the BeforeTargets and AfterTargets attributes so I could do the whole thing with a single call to MSBuild.exe and they would just chain together nicely.

Giving up on this, I now call MSBuild.exe three times. Once for the BeforeTeamCity target, once for the MSDeployPublish target, and once for the AfterTeamCity target. Works fine, go figure.

Michael12345
  • 2,520
  • 5
  • 23
  • 41