Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am creating one class library project. Now by default I have one App.Config file so that I am putting all environment specific data in that Config file.

Now based on the Environment (whether Dev / Test / Production), I am planning to have three App.Config files in VS 2010 such as

App.Dev.Config

App.Test.Config

App.Prod.Config

Wondering how would the application know which config file to use.

Anyone implemented this scenario. Any Code samples / Articles would be helpful.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
214 views
Welcome To Ask or Share your Answers For Others

1 Answer

The app will use the config file named YourExcecutable.exe.config which is by default the file App.config included in your (executable) project. Note, that .NET only loads one config file for the whole application. You cannot use multiple configuration files (i.e. one per library project) without coding.

  1. Option: You can use postbuild events and different solution configurations to copy one or another App.Config file to the output folder

  2. Option: You can use the ConfigurationManager Class to load an alternate config file by code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...