Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing another projects app.config properties?

Tags:

I have two projects within my solution, for this example I will call them project A and B.

Project B references A. Can Project B access the app.config properties of project A?

I wish to access an app key string within the app.config of A.

string tfsUri = ConfigurationManager.AppSettings["TfsUri"]; 
like image 213
user1352057 Avatar asked Apr 01 '14 12:04

user1352057


People also ask

Where are app config files stored?

The file is stored inside this path "bin/debug/app. config", if you make changes while debugging, those changes should appear there. Just remember that this file is overwritten with the "app. config" from the project root each time you run the application on Visual Studio IDE.

Is app config and web config are same?

When using Windows Forms or WPF etc, then you have the app. config which also stores ConnectionStrings. So yes they are similar but have different purposes.


1 Answers

That's generally not a good idea, as you introduce hard dependencies between the projects. So if you can copy-paste config value, that will make your projects self-contained (however, this introduces duplication of config value).

You can also automate this, so that when you build a project the configuration dependency is automatically resolved.

Having-said this, there are other options, and in each case you may prefer to use something else. Your other options are:

  • Use configuration transformation, like SlowCheetah
  • Add whole config file from one project to another "as a link"
  • Inject configuration value to your class (instead of reading it from config)
  • Read other project's config file in runtime, by using things like ConfigurationManager.OpenExeConfiguration
  • Also check out How to select different app.config for several build configurations
like image 145
oleksii Avatar answered Sep 30 '22 05:09

oleksii