How can I configure transformation of App.conf file in Visial Studio

No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.

I want to build different assemblies for my Windows Forms applications but I found what Win Forms application does not contains App.Debug.conf etc.

For example in Web App I can click to "Add config transofm" and get new configuration file for current release configuration.

How can I build applications with different release configurations(Debug, Release, etc.)?

1 Answer

Internet users could send Bitcoin Tips to you if they like your answer!

You can use this article by Oleg Sych.

But here are short instructions:

  1. Add a config file for each configuration to the project.

    You need to add App.Debug.config and App.Release.config but your solution may contain another configurations. For it you can use this pattern: App.<ConfigName>.config

    1. Open .csproj file for editing(before that you should unload project)

    I think you know how you can do it :)

  2. Add information about binding main App.config

    Find the project file section that contains all App.config and App.*.config references. You'll notice their build actions are set to None:

    <None Include="App.config" />
    <None Include="App.Debug.config" />
    <None Include="App.Release.config" />
    <None Include="App.<ConfigName>.config" />

    Find the Content tags and add this strings:

    <Content Include="App.config" />
    <Content Include="App.Debug.config" >
    <Content Include="App.Release.config" >
    <Content Include="App.<ConfigName>.config" >
  3. Enable transformations in the *.csproj file

    In the end of *.csproj file put this:

    <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
      <Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
        <!-- Generate transformed app config in the intermediate directory -->
        <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
        <!-- Force build process to use the transformed configuration file from now on. -->
          <AppConfigWithTargetPath Remove="app.config" />
          <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
User rating:

I have question about this item:

Enable transformations in the *.csproj file

Do need I to put this strings before </Project> tag?

User rating:

Yes of course :)

User rating:

Ok. Thanks :)


Too many commands? Learning new syntax? is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your productivity with!

Post Answer