Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 519
CharithJ Avatar asked Feb 23 '11 04:02

CharithJ


People also ask

What should I put in a config file?

A configuration file, often shortened to config file, defines the parameters, options, settings and preferences applied to operating systems (OSes), infrastructure devices and applications in an IT context.

How do I add a section in app config?

We will start with creating an class that can store the instance settings (the <add> element), then we'll create a collection that can store our instances (the <instances> element) and then we'll create the class to manage the Configuration Section (the <sageCRM> element).

Should config files be in source control?

While it is necessary when using source control to store the web. config files in the repository, it is best practice to separate out any sensitive or environment specific values to separate files and exclude those files from source control. This article explores some best practices on how to do that.

What are configuration files in an application?

An application configuration file is an XML file used to control assembly binding. It can redirect an application from using one version of a side-by-side assembly to another version of the same assembly. This is called per-application configuration.


2 Answers

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.

like image 51
mellamokb Avatar answered Sep 19 '22 22:09

mellamokb


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.

like image 45
Josh Avatar answered Sep 20 '22 22:09

Josh