|
.Net provides Config files to store configuration values for applications. Each application (an executable or web application) can have its own config file. Two common config files are:
For example, a standard solution might include a web application (with a web.config) and a Console application to run unit tests (with a App.Config). There are challenges with config files for both testing and deployment:
This prompts three questions:
Let's look at each one of these:
Should you include the config in the project file?
Having a file in the physical directory, and having the file listed in the project are two different things. If in Visual Studio, Solution Explorer, you click "Show all files", you'll see all the files in the physical directory that aren't listed in the proj file.
| Pro | Con | |
| Include |
|
|
| Exclude |
|
|
How do you get the latest version of the config?
Two ways to get the latest version of a file:
How do you localize the config for a specific environment?
Perhaps the best way to localize configs for your environment is to have a localized version in another folder, and then have a DOS script that can copy that localized version into the project folder.
Suggestion
Based on these questions, I've found the following parameters to work well.
| Config File | Include/Exclude | Why | How to get latest | Localize |
| Web.Config - used for web application. | Exclude |
| Manually push from VSS | Need to localize it the first time, but then do nothing afterwards because a get-latest won't override it. |
| App.Config - used for Unit Tests. | Include | Needed for NUnit | Automatic when getting project within VS.Net | Run DOS script to copy in your localized files. |
In terms of keeping configs updated, I find the following process helpful:
For AppSettings, I like the "user.config" approach. This is enabled by
adding a "file" attribute to the <appSettings> element in app.config
or web.config, as in: