4

I'm using .NET MVC

I have about 10 properties I want to store in a configuration file (.config etc.), related to environment/deployment stuff, + other things for quick changes without doing dLL deploys.

I'm using Team foundation service for CI builds etc, and my web.config is obviously under version-contrl.

What I'd like to do is have a settings.config (that's not in version control) file to store these, am I able to do this?

Or does it need to be in web.config?

williamsandonz
  • 15,864
  • 23
  • 100
  • 186
  • 1
    Not sure if it's relevant in your situation, but did you know you can have child elements of `Web.config`, called `Web.Debug.config`, `Web.Release.config` etc that overwrite nodes in the parent .config file depending which config you are building? – meataxe Jun 24 '13 at 01:19

1 Answers1

8

To answer the title question, yes you can store settings in a separate config file, to do so you need to define the configSource property of appSettings element

E.g.

<appSettings configSource="settings.config" />

and in the settings.config file

<?xml version="1.0" encoding="UTF-8"?>
<appSettings>
    <add key="settingKey" value="environmentValue" />
</appSettings>

However, for the sake of environment specific settings, you may want to look at config transforms. Setting up a transform config for each environment then deploying to that environment with the specified build configuration.

E.g. Web.Dev.config (provided you have setup a 'Dev' build configuration)

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="settingKey" 
      value="devEnvironmentValue" 
      xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
  </appSettings>
</configuration>

More details of build configuration and config transforms here: http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx

Or you could take advantage of TFS features and parameterize the environment variables, I don't have a lot of experience with this, but the following should help: http://ig.obsglobal.com/2013/02/tfs-and-continuous-deployment-part-4-parameterized-deployments/

Brent Mannering
  • 2,316
  • 20
  • 19
  • Thanks for your answer. I've since noticed this post http://stackoverflow.com/questions/6940004/asp-net-web-config-configsource-vs-file-attributes, it's very handy/related on the subject. Think I will use the "file" attribute instead of configSource, because it allows merging – williamsandonz Jun 24 '13 at 01:55