C # VS.NET 2008 Changing Configuration Settings

Is there a way to have different application settings for each build configuration?

I would like to be able to prepare several configurations with different settings, instead of changing the settings and building, repeat the repeat.

Thanks in advance!

+3
source share
4 answers

I know little about the architecture of appsettings (I never used it), but you can define different values ​​for constants using a bit of MSBuild magic.

Create two .cs files, Constants1.cs and Constants2.cs (or name them after your configurations).

In each file, define the Constants class (or something else) - but do it as if each file was the only definition (i.e. use the same class name). Typically, this should simply define the public static readonly fields - do not use const , as this may cause you problems with partial assemblies.

Now upload the project file and edit it. Find entries that look like this:

  <Compile Include = "Constants1.cs" />
     <Compile Include = "Constants2.cs" />

and change them like this:

  <Compile Include = "Constants1.cs" Condition = "'$ (Configuration)' == 'Debug'" />
     <Compile Include = "Constants2.cs" Condition = "'$ (Configuration)' == 'Release'" />

Finally, save and reload the project. Now only one of the files will actually be created at a time, depending on the build configuration.

+1
source

You can add probuild or postbuild task to proj, you have access to ConfigurationName. It would be pretty easy to do something like "copy Web.config.debug Web.config"

0
source

In addition, MS promised to add this feature to VS 2010.

0
source

What do you mean by "application settings"? Project property for each configuration, for example Debug or Release? Or defirent the app.conf file for each of them?

First of all, you can create several configurations with the appropriate settings and use Batch Build to build them in turn. http://msdn.microsoft.com/en-us/library/169az28z.aspx

or, as Google Ninja said, use the pre-build task: del Web.config app.config copy Web.config.Debug Web.config (create several configuration files in front of it)

0
source

All Articles