C# - Use configuration file in Debug mode -


I came to know a few days ago that we Can use configuration files in NET and try to use it in my applications.

Firstly, configuring the use of the configuration file correctly is boring:

  • The name of the configuration file should be the same (understandable)
  • Then
  • When the file is added, go into its properties and change it to copy the file to the output directory (less understandable).
  • The configuration file is not considered in debug mode (due to * .vhosts.exe)

    I have time to understand why it has not taken this file

    So the question is very simple, how can I fix it and use configuration files in debug mode?

    I will use it to configure my trace switch. > My app here The config file is:

      & lt; Configuration & gt; & Lt; AppSettings & gt; & Lt; Add Key = "A" Value = "B" /> & Lt; / AppSettings & gt; & Lt; System.diagnostics & gt; & Lt; Switch & gt; & Lt; Add name = "myFirstSwitch" value = "1" /> & Lt; Add name = "MySecondSwitch" value = "error" /> & Lt; / Switch & gt; & Lt; /system.diagnostics> & Lt; / Configuration & gt;   

    Thanks.

    I think the wrong way you have made your config file is:

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

    2. Select the application configuration file template and then click Add. The file named App.config has been added to your project.

      When you create a project and this config file is automatically copied to the build folder, it works in both Debug and Release mode.

      Enter image details here

Comments