I'm building an ASP.NET app in VS2010. I have a number of separate assemblies (class libraries) and corresponding Test projects for each.
In one of the class libraries I use an App.config file to store settings. The assembly itself uses the following code to retrieve settings:
string tmp = ConfigurationManager.AppSettings["mySetting"];
The problem is that when I try to create a Unit Test in a separate test project, the test does not pick up the setting in the App.config file. If I COPY the App.config file into the Test project, it works.
How can I ensure that each assembly uses its own copy of an App.config file. It would introduce problems if I had to copy config files around. There's an additional problem because there may be multiple config files, one per assembly - how could they all co-exist in a single test project anyway?
Thanks!
App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.
The application configuration file usually lives in the same directory as your application. For web applications, it is named Web. config. For non-web applications, it starts life with the name of App.
Web. Config is used for asp.net web projects / web services. App. Config is used for Windows Forms, Windows Services, Console Apps and WPF applications.
Well, if you need a App.config file shared across several projects, I would simply "Add as Link" the original App.config file in each project.
Let's say you have ProjectA with the original App.config. Then you have ProjectATest1 and ProjectATest2. In each of the TestX project:
It'll create a App.config shortcut in each TestX project. If you change it, it will change everywhere.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With