What's the best way to allow team members to customize their own app.config, but keep an authoritative version in version control? Is it best to exclude all *.config files from source control, and use an app.config.template file in version control?
The template method is the best method I've seen. If you can automatically determine what it should contain (such as by running a script to check for the appropriate values), then you can include that in your build process and automatically create the file from the template. If you can't automatically determine what it needs to contain, be sure that your build process will check for the config file and provide the developer with useful guidance as to what he should configure before the build will work.
You'll want your scm to ignore the config file itself so that your devs don't accidentally commit it to the repository.
There is no one "best way". It depends on the team and the environment.
Talk it over with your team members and decide what will work for your situation. Giving you a "this is the best way" may not work in your specific circumstances.
For a long time I'd always thought that Microsoft made configuration management a complete pain in the ass.
Luckily now you can externalise settings in the appSettings
and connectionStrings
sections etc. by using the file
property for appSettings and the configSource
property for other sections.
The documentation for configSource is hidden away in MSDN unfortunately, which is why I assume it isn't more widely known. The documentation provided is also rather bland, but there's a much better explanation here:
Best Practices for Configuring ASP.NET ConnectionStrings and AppSettings in Web.Config
To paraphrase, you can do stuff like this:
<appSettings file="webAppSettings.config">
<add key="UseCache" value="True"/>
<add key="MapsKey" value="1234567890-AA"/>
<add key="SMTPServer" value="smtp.peterkellner.net"/>
</appSettings>
<connectionStrings configSource="WebConnectionString.config">
</connectionStrings>
You can use this method in conjunction with the template method to handle settings for difference environments too.