ZZZ
ZZZ

Reputation: 275

How do I get the App.Config from a different project within the same solution

I have 2 projects {A,B} within the same solution, I would like to access the app.config that is in project A, from project B. The following code is run in a class that is within project B. AssistantClass is within Project A, I am trying to access the bin path, and get the Execonfigs, but it is giving me a wrong path that is within project B not A where the app.config is. Any ideas ?

string path = Assembly.GetAssembly(typeof(AssistantClass)).Location;
var localV = System.IO.Path.GetDirectoryName(path);
var locs = ConfigurationManager.OpenExeConfiguration(localV);

Upvotes: 0

Views: 298

Answers (1)

pepalguru
pepalguru

Reputation: 11

When you try to get the path of AssistantClass, it is expected that it will give path to project B's bin folder, as it is referenced into it and is part of the assembly running from B. You have to use relative paths (..\..\ProjectA\App.config) to access that config file. But this is also not an idle solution, as when you deploy this assembly, the solution structure may not be created as-is. You need to make sure that while compiling, the needed config files are output to the same relative folder every time.

Upvotes: 1

Related Questions