Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing settings file between projects in VS2013

I have multiple projects that are accessing the same settings (they were a single project, but I'm re-factoring). What I would like to do is the equivalent of:

"Add Existing Item" -> "Add Link"

The projects are a mixtutre of both C# and VB. When I try to do add as link, it does bring the settings file in, but it doesn't recognise it. I actually get the error when trying to load the settings:

Error HRESULT E_FAIL has been returned from a call to a COM component.

Is there a way to tell the project to use a specific settings file (either inside or outside the IDE)?

like image 948
Paul Michaels Avatar asked Dec 06 '13 15:12

Paul Michaels


People also ask

How do I share files between projects in Visual Studio?

Creating a Shared Project To create a new Shared Project, navigate to File > New > Project. In Visual Studio 2019, enter shared in the search box on the Create a new project page. Select the Shared Project template and then select Next.

What is difference between solution and project in Visual Studio?

A project is contained within a solution. Despite its name, a solution isn't an "answer". It's simply a container for one or more related projects, along with build information, Visual Studio window settings, and any miscellaneous files that aren't associated with a particular project.

What is a solution in dot net?

Solutions are the containers for all your work in VS.NET. A solution contains a project for each build output. (For example, if you want to build a DLL, an EXE, and an MSI Installer file, your solution will contain three projects.) Projects themselves contain source files.

What are solutions in Visual Studio?

A solution is simply a container Visual Studio uses to organize one or more related projects. When you open a solution, Visual Studio automatically loads all the projects that the solution contains.


2 Answers

I usually put these things in a common library. When sharing settings, you probably share more than just that, so combine it then. When marking the settings as public instead of internal, you can access them across the other projects.

For future reference:

The solution was to add the Settings file 'as link' to the project, right click and hit 'Run Custom Tool' where the Custom Tool property of the Settings file is 'SettingsSingleFileGenerator'.

Note that this solution is not favored, since it depends on manually updating the settings designer file by performing the above actions.

like image 182
Patrick Hofman Avatar answered Sep 24 '22 06:09

Patrick Hofman


Taken from MSDN: Add Multiple Settings

"In Solution Explorer, drag the new Settings file into the Properties folder. This allows your new settings to be available in code.

Add and use settings in this file as you would any other settings file. You can access this group of settings via the Properties.Settings object."

I have done this,and it works for me in my C#/VB mixed projects. Hope this helps

like image 39
PeonProgrammer Avatar answered Sep 24 '22 06:09

PeonProgrammer