Accessing another project's settings file

The answer if you are using C#:
The very simple answer is to right click on proj2, choose the settings tab. On the top, you will find the access modifier of the settings class is: internal, change it to public. Add a reference to the proj2 in the proj1 in order to see the proj2 Settings class. That's all.


Option A : parse the values out of the other assembly's configuration file (where the settings are stored)

Option B : create a public class in Proj2 that exposes the necessary values from its settings as static properties, then reference the assembly in Proj1 and consume the values from that class.

Option C : If you want to expose ALL the settings, you can modify the access of the settings class from internal to public.

I'm sure there other ways as well.


I'll repost the contents of @Kildareflare's link for future reference. Still works in VS2015, but for myself I think I prefer "Option B" above.

Getting access to Settings in another project

One of the new cool features of Visual Studio 2005 is the new property editor. With this property editor you can easily add setting to your application. But there is a problem the way it's implemented. Let me explain you why.

Usually the settings are specific to a project. When you add a setting in a project a special custom tool associate with the setting file generates a new class which you can use to access it. What is good about this class is it’s strong typed. But behind the scene it’s just getting a key from an xml file. This generated class is set as "internal sealed". This prevent from being accessed from any other assembly. What if you want to centralize where you edit these settings.

After many attempt to expose it I found a quick an easy way to do it. Let’s say we have 2 project in our solution: an Engine and a WinApp. Each have settings but we want them to be editable from WinApp. Here is what it look like.

Settings Before

If you want to get access to Engine settings here the trick: Add a link file.

Add Link

The link file will be compiled as part as you WinApp project. The setting class will still be internal and sealed but to WinApp project instead of Engine.

Here is the final result:

Settings After

Notice that I added a folder with the same name as my Engine project. This will be helpful if you want to add settings from many projects.

With this in place you can access you engine setting the way from you engine class as from your WinApp class. You may omit the “Engine” part from your engine class because you should be in the same namespace. Here is what it should look like:

namespace WinApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void AccessConfig()
        {
            Engine.Properties.Settings.Default.EngineSetting = "test";
        }
    }
}