question

prathamjain-2257 avatar image
0 Votes"
prathamjain-2257 asked orhanori answered

Add Config Transforms for app.config in WPF Application

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

windows-wpf
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@prathamjain-2257
Did you want to convert Web.config to App.config in Visual Studio and to make multiple WPF apps to share one App.Config? Did you try to copy the web.config content and then paste it to the App.config?

0 Votes 0 ·

1 Answer

orhanori avatar image
0 Votes"
orhanori answered

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>





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.