F
F
Frodo2012-12-27 14:07:10
.NET
Frodo, 2012-12-27 14:07:10

One app.config for two projects in solution?

There are two projects in one solution, one, the main one, has a config file with a connection string, the second, a child, does not have a config file, but must read the connection string from the config of the first one.
The option "add the config of the first to the second as a link" is not good. It is necessary that by launching the executable of the second project (both executables and the config file are in the same folder), it can work normally with the config of the first one.
The problem is that it starts looking for a file called "project2.exe.config" and when it doesn't find it, it crashes.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dmomen, 2012-12-27
@dmomen

www.codeproject.com/Articles/14465/Specify-a-Configuration-File-at-Runtime-for-aC-Co

F
Frodo, 2012-12-27
@Frodo

The problem was solved rather unpretentiously, I'll leave it here, maybe it will come in handy for someone:
string path = Path.Combine(Application.StartupPath, "project2.exe");
if (File.Exists(path))
{
Configuration conf = ConfigurationManager.OpenExeConfiguration(path);
ConnectionString =
conf.ConnectionStrings.ConnectionStrings["connectionString"].ConnectionString;
}

A
Alexey Buraikin, 2012-12-27
@bstdman

Why not make a class with XML serialization a separate Singleton assembly? The settings will be in a single file with a given name, and not necessarily in the same folder as the exe.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question