Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET different application settings for development and release

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?

like image 615
djskinner Avatar asked Mar 12 '10 12:03

djskinner


3 Answers

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
like image 75
Leigh S Avatar answered Nov 13 '22 07:11

Leigh S


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.

like image 25
Gerrie Schenck Avatar answered Nov 13 '22 09:11

Gerrie Schenck


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.

like image 1
Jamie Chapman Avatar answered Nov 13 '22 07:11

Jamie Chapman