views:

223

answers:

2

Following my previous question, now I have 2 projects: one Console Project and a Library Project. They also have their respective unit test projects. When I run a test for the console project that uses a method from the library project and the library project needs an app.config setting, that setting must be in the console test project's app.config. What I have to do to make it read the setting from the library project app.config, so then I do not have to duplicate the setting across multiple app.config?

Update I don't want to use the same App.Config for both projects. What I am having to do now, but don't want to do anymore, is copying all the library app.config settings into the console project settings.

+2  A: 

One option I have used is to share the config file via a soft link. First create the app.config file in one project, then add it to the other:

  1. Right-click the other project.
  2. Select Add -> Existing Item and navigate to thh app.config.
  3. Don't click Add! Click the little arrow on the right side of the button, and select Add as Link.

This of course assumes you can use the same file for both projects.

UPDATE: I do not know which part of the app.config you need to share. But for the appSettings section, you can include the contents of another file via the "file" attribute.

<appSettings file="commonSetting.config">

</appSettings>

Maybe something similar can be used in your case?

Jeremy
Please read the update in the question. Your answer would be helpfull for my previous question, but not for this one.
Jader Dias
Now your answer in conjunction with Decker97 answer is very helpfull! Thanks
Jader Dias
+2  A: 

If the library project is a class library, then it needs a context to execute in. VS will not read the app.config file for a class library, it only reads the app.config file from the executing context, from what I can tell. The setting has to be in the console app.config because that is the context for execution. If you are running unit tests and they are the executing context then they will need their own app.config as well.

Decker97