I have a console application that uses a database connection string which is defined in app.config. I have a few transformations to change the string depending on the build configuration.
I also have a few post-build events that copy app.config to other projects output. The problem is post-build event fires first and I copy the untransformed app.config. Later the transformation task kicks in and apply the transformation (so I know it works). I use with Visual Studio 2010 and .NET 4.
Right now the actions are [1], [3], [2], I need to reorder them to [1], [2], [3]
1) Build
2) Run transformation
3) Run post-build event
Here is my transformation from .csproj
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="Transformation" Condition="exists('app.$(Configuration).config')" >
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
And this is my post-build events
<PropertyGroup>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>copy $(ProjectDir)app.config $(OutDir)\TH.Presentation.LocalAgent\$(TargetFileName).config
copy $(ProjectDir)app.config $(OutDir)\TH.Services\$(TargetFileName).config</PostBuildEvent>
</PropertyGroup>
Any help would be greatly appreciated