CharithJ
CharithJ

Reputation: 47530

Can I add conditions in app.config file?

Is it possible to add conditions in app.config file?

I do below in the C# code and I want to do something similar in my app.config file too.

#if (Debug)
.......
#else
.....
#endif

Upvotes: 20

Views: 14718

Answers (3)

Joe Enos
Joe Enos

Reputation: 40393

You should be able to do something like this programatically, by putting the relevant sections in two different config files, then at app-start time, load the appropriate config file. The majority of your config would be in the main app.config, and there would be a second config file for the rest.

I don't have the syntax offhand, but it's basically the same idea as having a user.config with user-specific configurations.

Upvotes: 2

Josh
Josh

Reputation: 69262

That is not possible, although in Visual Studio 2010 there is a feature that lets you apply configuration-dependent transformations to the Web.config file, but only when publishing using msdeploy.

There is no such transformation for executable applications. You might want to look into using a post-build action to copy a release or debug config file.

Upvotes: 4

mellamokb
mellamokb

Reputation: 56769

You can try some type of app.config transforms like this: http://fknut.blogspot.com/2009/11/appconfig-transformation-with-new.html.

Or have multiple app.config files like app.config.debug and app.config.release, and use the appropriate one in your build.

Upvotes: 11

Related Questions