Overriding Individual Application Settings

You may have the situation where you want to be able to override application settings for a .NET application only for your particular instance of the application. This is often the case when you are developing the application, you need to change only the local settings, but you don't want to change the config file that is part of the project and under source control. Here we'll explain the solution that .NET provides but isn't so well known.
We'll use the ASP.NET web.config file for this example.

First, you place the attribute file="user.config" in the web.config file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<appSettings file="user.config">
               <!-- your application settings -->
	</appSettings>
	<system.web>
		<!-- standard asp.net configuration nodes -->
	</system.web>
</configuration>
This will point to the named file for application setting overrides. Then you can create the user.config file in the application directory to hold your personal overrides for the default application settings. The file should look like this:

<appSettings>
	<add key="key" value="value" />
</appSettings>

Note that appSettings is the root node. The user.config file does not have to exist. .NET will just ignore a missing file and use the default values in web.config.

If you do create this file make sure you do not put it into the project (and, thus, source control) so as to avoid overwriting individual's settings.

This solution can be found in the MSDN article: Team Development with Visual Studio NET and Visual SourceSafe - Chapter 4: Managing Dependencies which has lots of other details that are helpful to know if you are building software in a team environment.

Where to Next?

Wonder where to go next? You can read existing comments below or you can post a comment yourself on this article .


Consider making a donation
Please consider making a donation using PayPal. Your donation helps me to pay the bills so I can keep running Imar.Spaanjaars.Com, providing fresh content as often as possible.



Feedback by Other Visitors of Imar.Spaanjaars.Com

On Wednesday, August 01, 2012 8:34:56 PM Larry said:
If you want donations, you should keep your web links up to date.  The link for "Team Development with Visual Studio NET and Visual SourceSafe - Chapter 4: Managing Dependencies" on page "http://imar.spaanjaars.com/366/overriding-individual-application-settings" that links to "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/tdlg_ch4.asp" fails.
On Wednesday, August 01, 2012 8:51:57 PM Imar Spaanjaars said:
Hi Larry,

Thanks for bringing that to my attention. Fixed.

To put things in perspective:

- The article is over 6 years old
- Microsoft has a tendency to change links (especially back then)
- I didn't write the article
- It's scientifically proven that on my site there is no relationship between the accuracy of links and donations.

Imar

Talk Back! Comment on Imar.Spaanjaars.Com

I am interested in what you have to say about this article. Feel free to post any comments, remarks or questions you may have about this article. The Talk Back feature is not meant for technical questions that are not directly related to this article. So, a post like "Hey, can you tell me how I can upload files to a MySQL database in PHP?" is likely to be removed. Also spam and unrealistic job offers will be deleted immediately.

When you post a comment, you have to provide your name and the comment. Your e-mail address is optional and you only need to provide it if you want me to contact you. It will not be displayed along with your comment. I got sick and tired of the comment spam I was receiving, so I have protected this page with a simple calculation exercise. This means that if you want to leave a comment, you'll need to complete the calculation before you hit the Post Comment button.

If you want to object to a comment made by another visitor, be sure to contact me and I'll look into it ASAP. Don't forget to mention the page link, or the QuickDocId of the document.

For more information about the Talk Back feature, check out this news item.