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

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

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 - total earned - 0 BTC ($0 USD)

1
=
0
=
$0
Everyone, even non-registered users could send Bitcoin Tips to YOU if they are inspired by 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" >
      <DependentUpon>App.config</DependentUpon>
    </Content>
    <Content Include="App.Release.config" >
      <DependentUpon>App.config</DependentUpon>
    </Content>
    <Content Include="App.<ConfigName>.config" >
      <DependentUpon>App.config</DependentUpon>
    </Content>
    
  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. -->
        <ItemGroup>
          <AppConfigWithTargetPath Remove="app.config" />
          <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
            <TargetPath>$(TargetFileName).config</TargetPath>
          </AppConfigWithTargetPath>
        </ItemGroup>
      </Target>
    
SEND BITCOIN TIPS

I have question about this item:

Enable transformations in the *.csproj file

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

Yes of course :)

Ok. Thanks :)

4

Post Answer


Will Bitcoin Tipping become a new Internet Culture?


Please share our story! THANK YOU!