views:

891

answers:

6

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

I would like to be able to batch build a few configurations with different settings, instead of having to change the settings and build, rinse repeat.

Thanks in advance!

A: 

You could add a prebuild or postbuild task to the proj, you have access to the ConfigurationName from there. Would be fairly easy to do something like "copy Web.config.debug Web.config"

Matt Briggs
A: 

Besides all these, MS promised to add this feature in VS 2010.

Sergiu Damian
A: 

What do you mean under 'application settings' ? Project's property for each configuration such as Debug or Release? Or defirent app.conf file for each of them?

If first, you can create a number of configurations with suitable settings and use Batch Build to build them by turn. http://msdn.microsoft.com/en-us/library/169az28z.aspx

or as Google Ninja said, use pre-build task: del Web.config app.config copy Web.config.Debug Web.config (create a number of configuration files before it)

abatishchev
A: 

Thanks for all your answers, let me try to be more specific.

This is a desktop application, and I need to have a bunch of copies of the same application, but with different settings.

I already created all of my build configurations, but I have not been able to find where I can change the values of my settings per each build configuration.

The ideal situation would be for me to be able to go into the project settings, and change the values per each build configuration. So that would enable me to make changes to the code, do a batch build and have it build all versions with their individual settings in tact.

Quick example of the settings, username and password is stored as a setting which my program uses for ftp access. I want to hardcode these values as settings, but have different values for different builds that I will send off to different vendors.

Right now, I am just changing these settings, then building the project. Switch build configuration, change settings, build. Etc, etc, etc.

Any ideas? Thanks!

+1  A: 

I don't know much about the appsettings architecture (I've never really 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 a class called Constants (or whatever) -- but do it as if each file were the only definition (ie. use the same class name). Typically, this should just define public static readonly fields -- do not use const, as that can get you into trouble with partial builds.

Now Unload your project file and Edit it. Find the entries that look like this:

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

and change them like so:

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

Finally Save and Reload your project. Now only one of the files will actually be built at a time, depending on your build configuration.

Miral
awesome, thanks miral!