Following my <a href="https://stackoverflow.com/questions/484087/how-to-avoid-duplicate-app-config-using-visual-studio-2008-unit-testing" rel="nofollow">previous question</a>, 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?
<strong>Update</strong> 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.Answer1:
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.Answer2:
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:<ol><li>Right-click the other project.</li> <li>Select Add -> Existing Item and navigate to thh app.config.</li> <li>Don't click Add! Click the little arrow on the right side of the button, and select Add as Link.</li> </ol>
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.
Maybe something similar can be used in your case?