Introduction
I have tried to make it very simple to add the transformation files of app.config file into .NET Windows Service.
Step by Step
Step 1
Add the transform files manually on the project folder where the app.config is, for example, I have added three transformation files as below.
- App.FSTTransform.config
- App.LIVETransform.config
- App.UATTransform.config
Step 2
Right click on the .csproj project file from the project folder and edit that with any editor.
Step 3
On the opened XML file, replace the below code:
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
by the below XML:
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="App.FSTTransform.config">
<DependentUpon>
App.config
</DependentUpon>
</None>
<None Include="App.UATTransform.config">
<DependentUpon>
App.config
</DependentUpon>
</None>
<None Include="App.LIVETransform.config">
<DependentUpon>
App.config
</DependentUpon>
</None>
</ItemGroup>
Step 4
Add below XML target after the Import <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
:
<Target Name="AfterCompile">
<TransformXml Source="App.config"
Destination="App_FST.config" Transform="App.FSTTransform.config" />
<TransformXml Source="App.config"
Destination="App_UAT.config" Transform="App.UATTransform.config" />
<TransformXml Source="App.config"
Destination="App_LIVE.config" Transform="App.LIVETransform.config" />
</Target>
Step 5
Define the TransformXML
on before the <PropertyGroup>
on top of the project XML file as below:
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
Final Step
Go to Visual Studio and reload the project. Build the project.