Add Config Transforms for app.config in WPF Application

pratham jain 1 Reputation point
2021-02-01T17:53:18.743+00:00

Hi All,

I have several C# WebAPI applications where I have added configuration transform files for web.config for different deployment environments.

Now, I have a WPF application which includes app.config file and I want to add the configuration transforms to this app.config for various deployment environments like production, test etc. But Visual Studio Professional 2019 is not displaying any option to add config transform to this app.config file on right click.

Please advice how can I add configuration transforms to app.config in WPF Application ASAP.

Regards,
Pratham

Developer technologies | Windows Presentation Foundation
{count} votes

1 answer

Sort by: Most helpful
  1. Ori 6 Reputation points
    2021-07-30T15:30:49.6+00:00

    Hello,

    You have to do it manually by editing your .csproj file.

     <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
      <AppConfig>App.Release.config</AppConfig>
    </PropertyGroup>
     <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
       <AppConfig>App.Debug.config</AppConfig>
     </PropertyGroup>
    

    And to display config files together, under App.config in the Solution Explorer;

    <ItemGroup>
      <None Include="App.config"/>
      <None Include="App.Debug.config">
        <DependentUpon>App.config</DependentUpon>
      </None>
      <None Include="App.Release.config">
        <DependentUpon>App.config</DependentUpon>
      </None>
    </ItemGroup>
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.