<p>In a .NET project, say you have a configuration setting - like a connection string - stored in a app.config file, which is different for each developer on your team (they may be using a local SQL Server, or a specific server instance, or using a remote server, etc). </p>

<p>How can you structure your solution so that each developer can have their own development "preferences" (i.e. not checked into source control), but provide a default connection string that is checked into source control (thereby supplying the correct defaults for a build process or new developers).</p>

<p><hr />
Edit: Can the "<code>file</code>" method suggested by @Jonathon be somehow used with the <code>connectionStrings</code> section?</p>

[{'answer_id': 19359, 'author': 'Scott Muc', 'author_id': 1894, 'author_profile': 'https://Stackoverflow.com/users/1894', 'pm_score': 0, 'selected': False, 'text': "<p>I always make templates for my config files. </p>\n\n<p>As an example I use NAnt for the building of my projects. I have a file checked in called local.properties.xml.template. My NAnt build will warn the developer if local.properties.xml does not exist. Inside that file will be workstation specific settings. The template will be checked into source control, but the actual config won't be.</p>\n"}, {'answer_id': 19360, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 0, 'selected': False, 'text': '<p>I use quite archaic design that just works.</p>\n\n<ul>\n<li>/_Test__app.config</li>\n<li>/_Prod__app.config</li>\n<li>/app.config</li>\n</ul>\n\n<p>Then in my nant script, I have a task that copies, the current build environment plus _ app.config and copy it to app.config.</p>\n\n<p>Its nasty, but you can\'t get in between providers and ConfigurationManager to spoof it, by saying providers look at "dev" or "prod" connection string and just have 3 named connection strings.</p>\n\n<p>nant task:</p>\n\n<pre><code>&lt;target name="copyconfigs" depends="clean"&gt;\n  &lt;foreach item="File" property="filename" unless="${string::get-length(ConfigPrefix) == 0}"&gt;\n   &lt;in&gt;\n     &lt;items&gt;\n       &lt;include name="**/${ConfigPrefix}App.config" /&gt;\n       &lt;include name="**/${ConfigPrefix}connectionstrings.config" /&gt;\n       &lt;include name="**/${ConfigPrefix}web.config" /&gt;\n     &lt;/items&gt;\n   &lt;/in&gt;\n   &lt;do&gt;\n    &lt;copy overwrite="true" file="${filename}" tofile="${string::replace(filename, ConfigPrefix,\'\')}" /&gt;\n   &lt;/do&gt;\n  &lt;/foreach&gt;&lt;/target&gt;\n</code></pre>\n'}, {'answer_id': 19361, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 3, 'selected': True, 'text': '<p>AppSettings can be overridden with a local file:</p>\n\n<pre><code>&lt;appSettings file="localoveride.config"/&gt;\n</code></pre>\n\n<p>This allows for each developer to keep their own local settings.</p>\n\n<p>As far as the connection string, in a perfect world all developers should connect to a test DB, not run SQL Server each.</p>\n\n<p>However, I\'ve found it best to keep a file named Web.Config.Prd in source control, and use that for build deployments. If someone modifies web.config, they must also add the change to the .PRD file...There is no good automation there :(</p>\n'}, {'answer_id': 19375, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n  <p>Can the "file" method suggested by @Jonathon be somehow used with the connectionStrings section?</p>\n</blockquote>\n\n<p>No, but there is nothing stopping you from storing the ConnectionString as an AppSettings key.</p>\n'}, {'answer_id': 19380, 'author': 'Scott Muc', 'author_id': 1894, 'author_profile': 'https://Stackoverflow.com/users/1894', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n  <p>Edit: Can the "file" method suggested\n  by @Jonathon be somehow used with the\n  connectionStrings section?</p>\n</blockquote>\n\n<p>Or you can have multiple connection strings in the checked in config file, and use an AppSettings key to determine which ConnectionString is to be used. I have the following in my codebase for this purpose:</p>\n\n<pre><code>public class ConnectionString\n{\n    public static string Default\n    {\n        get \n        { \n            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["DefaultConnectionStringName"]))\n                throw new ApplicationException("DefaultConnectionStringName must be set in the appSettings");\n\n            return GetByName(ConfigurationManager.AppSettings["DefaultConnectionStringName"]);\n        }\n    }\n\n    public static string GetByName(string dsn)\n    {\n        return ConfigurationManager.ConnectionStrings[dsn].ConnectionString;\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/19355', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/708/']