Question

I've got the following MSBuild script:

<Copy SourceFiles="$(AdminPath)\web.config" DestinationFiles="$(AdminPath)\tmpweb.config" />
<TransformXml Source="$(AdminPath)\tmpweb.config" Transform="$(AdminPath)\web.$(Configuration).config" Destination="$(AdminPath)\web2.config" />
<Copy Sourcefiles="$(AdminPath)\web2.config" DestinationFiles="$(AdminPath)\web.config" OverwriteReadOnlyFiles="true" />
<Delete Files="$(AdminPath)\tmpweb.config;$(AdminPath)\web2.config" />

However, although web2.config is deleted, tmpweb.config is not "because it is being used by another process" (error MSB3061).

How do I get around this?

I've tried copying the file as described in this blog post but that doesn't seem to work either.

Was it helpful?

Solution

I was using v10 of the publishing tasks. I should have used v12.

For future reference using the following:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

OTHER TIPS

It's not the MSBuild who's locking the file, but the TransformXml task and it's mighty annoying under certain deployment strategies. You can try workarounds from the bug report, personally I wrap it in a custom task via either TransformXml task class or XmlTransformation class directly which gives an added benefit of extra flexibility, eg logging via IXmlTransformationLogger, ie downgrading certain warnings to debug messages to keep the log less noisy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top