[ACCEPTED]-App.config in Test Projects-.net-assembly

Accepted answer
Score: 56

Well, if you need a App.config file shared across 7 several projects, I would simply "Add as 6 Link" the original App.config file in each project.

Let's 5 say you have ProjectA with the original App.config. Then you 4 have ProjectATest1 and ProjectATest2. In each of the TestX project:

  1. right click on the solution name in Visual Studio
  2. select "Add Existing Item"
  3. navigate to the ProjectA App.config and select it
  4. click in the "Add" button down arrow
  5. select "Add as Link"

It'll 3 create a App.config shortcut in each TestX project. If 2 you change it, it will change everywhere.

Hope 1 this helps.

Score: 6

First up, if you're doing unit testing, then 13 you probably want to look at mocking out 12 the configuration, rather than reading it 11 anyway.

If you really want to make the config 10 available (I've done it for integration 9 tests in the past), then you can add a post-build 8 step to your assemblys (I'm assuming a 1-1 7 mapping of assembly to test-assemblies).

The 6 post build step (on your test assembly) would 5 look something like this:

  copy /y  "<path to your assembly under test>.dll.config" "$(TargetDir)\$(TargetName).dll.config"

Essentially, you're 4 copying the app.config that has been renamed 3 for you by visual studio for the assembly 2 you're testing, to match the expected configuration 1 name for your test assembly.

Score: 3

One should not have config files for the 10 assemblies. If you do so, every application 9 will end up having one config file per dll/reference 8 project.

The assemblies pick up the config 7 values from the application (Windows/Web) context 6 in which they are loaded.

So if you have 5 an WebApp, the assemblies would use WebApp's 4 web.config file to read the config values. Similarly 3 if you have a Windows App/Unit Test app, the 2 libraries should read the values from app.config.

Please 1 read this related question - C#.NET Compiling the settings.settings file from various projects in a solution into 1 config file

More Related questions