Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I store settings in a settings.config file in ASP.NET MVC?

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?

like image 411
williamsandonz Avatar asked Oct 21 '25 12:10

williamsandonz


1 Answers

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/

like image 52
Brent Mannering Avatar answered Oct 23 '25 02:10

Brent Mannering