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 :
- Configuration file should have the same name as the application (understandable)
- Then think to add the System.Configuration reference (understandable too)
- When file is added, go in it's properties and change it to copy the file in output directory (less understandable).
- Configuration file isn't taken into account in debug mode (because of *.vhosts.exe)
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>
&l开发者_Go百科t;/system.diagnostics>
</configuration>
Thanks.
I think you created your config file the wrong way, the right way is:
On the Project menu, click Add New Item. The Add New Item dialog box appears.
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.
精彩评论