Reputation: 1165
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!
Upvotes: 3
Views: 1257
Reputation: 13095
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.
Upvotes: 2
Reputation: 100366
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)
Upvotes: 0
Reputation: 1428
Besides all these, MS promised to add this feature in VS 2010.
Upvotes: 0
Reputation: 42258
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"
Upvotes: 0