I have next config in my Web.config file
<Target Name="UpdateWebConfigForProjectsBeforeRun">
<ItemGroup>
<FilesToTransofm Include="ProjectsDeployBin\Web.*.$(Configuration).config"/>
</ItemGroup>
<Message Text="Transform file: %(FilesToTransofm.Identity)" />
<TransformXml Source="web.config"
Transform="%(FilesToTransofm.Identity)"
Destination="web.config" />
</Target>
What i am trying to do its get all configs from ProjectsDeployBin directory and apply each file to main web.config.
After first transformation main web.config locked by msbuild.
So how can i fix this issue? Is there any other way to transform my web.config by collection of files? Thanks.
As you've noticed, the TransformXml task shipped with Visual Studio 2010 has a bug that leaves the source file locked.
To work around that, you can make a temporary copy of your source file before each transformation. Since you'll then be executing multiple tasks for each transform file (copy and transform), you'll need to switch to Target Batching instead of Task Batching.
Example:
<ItemGroup>
<FilesToTransofm Include="ProjectsDeployBin\Web.*.$(Configuration).config"/>
</ItemGroup>
<Target Name="UpdateWebConfigForProjectsBeforeRun"
Inputs="@(FilesToTransofm)"
Outputs="%(Identity).AlwaysRun">
<Message Text="Transform file: %(FilesToTransofm.Identity)" />
<Copy SourceFiles="web.config"
DestinationFiles="web.pre-%(FilesToTransofm.Filename).temp.config" />
<TransformXml Source="web.pre-%(FilesToTransofm.Filename).temp.config"
Transform="%(FilesToTransofm.Identity)"
Destination="web.config" />
</Target>
From a quick test, it looks like this bug is fixed in Visual Studio 2012, but I'm not able to find a reference / source that documents that, and the original Connect bug isn't viewable anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With