Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different application settings depending on configuration mode

Tags:

Is anyone aware of a way that I can set application (or user) level settings in a .Net application that are conditional on the applications current development mode? IE: Debug/Release

To be more specific, I have a url reference to my webservices held in my application settings. During release mode I would like those settings to point to http://myWebservice.MyURL.com during debug mode I would love those settings to be http://myDebuggableWebService.MyURL.com.

Any ideas?

like image 570
Maxim Gershkovich Avatar asked Jun 22 '10 04:06

Maxim Gershkovich


People also ask

What are application configurations?

An application configuration file contains settings that are specific to an app. This file includes configuration settings that the common language runtime reads (such as assembly binding policy, remoting objects, and so on), and settings that the app can read.

What is the difference between app config and web config?

config is parsed at runtime, so if you edit the web. config file, the web application will automatically load the changes in the config file. Â app. config is parsed at compile time, so if you edit the app.

What is app settings in web config?

The <appSettings> element of a web. config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work.


1 Answers

This is somewhat late to the party, but I stumbled upon a nice way of implementing the web.transform approach for app.config files. (i.e. it makes use of the namespace http://schemas.microsoft.com/XML-Document-Transform)

I think it is "nice" because it is a pure xml approach and doesn't require 3rd party software.

  • A parent / default App.config file is descended from, according to your various build configurations.
  • These descendants then only override what they need to.

In my opinion this is much more sophisticated and robust than having to maintain x number of config files which get copied in their entirety, such as in other answers.

A walkthrough has been posted here: http://mitasoft.wordpress.com/2011/09/28/multipleappconfig/


Look, Mom - No explicit post-build events in my IDE!

like image 63
ne1410s Avatar answered Oct 10 '22 20:10

ne1410s