Arnaud F.
Arnaud F.

Reputation: 8452

C# - Use configuration file in Debug mode

I discovered few days ago that we can use Configuration files in .NET and trying to use it in my applications.

First of all, configure correctly the use of configuration file is really borring :

It takes me time to understand why this file wasn't taken into account...

So question is pretty simple, how can I fix this and use configuration files in Debug Mode ?

I would use it in order to configure my trace switches.

Here is my App.config file :

<configuration>
  <appSettings>
    <add key="A" value="B"/>
  </appSettings>
  <system.diagnostics>
    <switches>
      <add name="myFirstSwitch" value="1" />
      <add name="MySecondSwitch" value="Error" />
    </switches>
  </system.diagnostics>
</configuration>

Thanks.

Upvotes: 0

Views: 1520

Answers (1)

BrokenGlass
BrokenGlass

Reputation: 160852

I think you created your config file the wrong way, the right way is:

  1. On the Project menu, click Add New Item. The Add New Item dialog box appears.

  2. Select the Application Configuration File template and then click Add. A file named App.config is added to your project.

This config file is automatically copied to the build folder when you build the project and works in both Debug and Release mode.

enter image description here

Upvotes: 4

Related Questions