Referencing External Configuration Files in .NET

It is always a good design practice to keep most generalized configuration settings in application configuration files (i.e., app.config or web.config) and very particular settings in external configuration files. Suppose you work with two different sets of connection strings (i.e., one for development and the other for production). You may also need to store other development- or production-specific settings separately. So, every time you want to test your application against one of these sets of databases, you will have to change an entire set of connection strings in your application config file, which involves more error-prone typing.

An alternative approach is to use two separate configuration files (such as dev.config and production.config) representing settings for development and production environments. You can then refer to a required .config file from your application configuration file using the attribute configSource, supported in .NET 2.0 and higher versions.

As an example, to refer to connection strings for use in your development environment, you would write the following in the application configuration file (app.config or web.config), which refers to the dev.config file stored in the config folder:

Similarly, you can use the configSource attribute with other config sections in the application configuration file, such as , , etc.

You can check if this attribute is supported for a given section through Visual Studio IntelliSense.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS