.NET different application settings for development and release
Asked Answered
S

7

7

I am using VS2010 C#.NET 3.5 and application settings (the Settings.settings file). What I want to do is have different settings for my development and production environments without having to litter my code with conditional statements checking for debug mode. What is the common approach to this problem?

Seleucia answered 12/3, 2010 at 12:16 Comment(0)
P
8

Or you can just create separate config files and call them:

Release.settings

Debug.settings

then setup conditional build events that copy the appropriate .config file to Settings.Settings


if $(ConfigurationName) == Debug xcopy debug.settings settings.settings
if $(ConfigurationName) == Release xcopy release.settings settings.settings
Pooch answered 12/3, 2010 at 13:35 Comment(1)
I am trying this option, but I am getting exit with code 4. I have a debug.settings and a release.settings in my App.configYeasty
C
1

Assuming you mean the values of the settings, I think the best way to do this is to put all the production environment values in a comment in the settings file. Or only set them when deploying the application.

There's no real built-in mechanism for this in .Net if that's what you're after.

At my current job we have a little command-line tool which will set all the values right for a given environment. The configuration is done in a database.

At my previous job we never copied the config file to the deployment directory, but rather changed the files manually if needed.

Capsize answered 12/3, 2010 at 12:18 Comment(1)
Tried using comments but they get deleted upon auto generation.Seleucia
C
1

We never override our web.config file on the production systems. If additional settings/keys are added, we paste them in at the time of publishing.

Clinkerbuilt answered 12/3, 2010 at 12:19 Comment(0)
C
1

If you use web deployment projects, you can set it up so that different parts of your web.config will be replaced. You can read more about them here: http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx.

Another approach, that we actually take at my current job is to have multiple web.config files - 1 for each environment (e.g. web.config, web.config.production). Then when we build for deployment, we use msbuild to automatically swap web.config.production in as the web.config.

Coracoid answered 12/3, 2010 at 13:3 Comment(0)
J
0

I think this is the lack of xxx.config files. That's why I use own config manager which can be used with different configurations on each machine where application is installed/executed.

James answered 12/3, 2010 at 12:24 Comment(0)
C
0

we use a NAnt script to build our solution, replace setting values in the config file, run tests and publish.

It's fairly straight forward once you've set it up once or twice.

Crowberry answered 12/3, 2010 at 13:16 Comment(0)
B
0

You can conditionally include items in build process, like

<ItemGroup Condition=" '$(Configuration)' == 'Debug' " ...

see https://mcmap.net/q/1480817/-debug-only-classes-and-resources-in-visual-studio-is-it-possible

Brann answered 27/5, 2015 at 11:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.