Add a settings file from another project (VB.NET)

January 01, 2014

I recently asked this question on Stack Overflow and, although the answer I got was correct, I thought I would write it up so that a clearer explanation was available for when I forget that I asked in the first place.

Here’s the link to the SO question (as I certainly wouldn’t want to claim credit for the solution): http://stackoverflow.com/questions/20427328/sharing-settings-file-between-projects-in-vs2013

I believe that the process for C# is different, and will try to cover that in a future post.

Disclaimer

If you do read the question, you’ll see that it was suggested to create the settings file in a single library and then expose that through a public method. I do agree that this would be the best way to do things. I’m not even saying that the way here is a good way to do things. However, I was in a position where it was the only feasible way to do things, given time constraints and project architecture. I intend, in the future, the refactor, and to have just such a library of settings. If you have time do do this now, or if you haven’t yet created your settings file then I would strongly suggest you go down this route and NOT read on.

Otherwise, read on

Okay, if you’re still reading then you’re either in the same position I was, or you didn’t read the disclaimer.

Adding a Settings file as a link

In the project that you wish to add the settings file, first, delete any existing settings files from inside (or outside) the “My Project” folder. Note that by default, “Show All Files” is turned off, and this can hide the “My Project Folder”, so make sure it’s on:

ShowAllFiles

MySettings

Now that’s deleted, selected the project and select “Add Existing Item”, and in the dialog that appears, find your settings file; then, and this is the important part, select “Ass as Link”:

AddAsLink

Okay, now you have a settings file from another project. Now you need to set the namespace and the custom tool. They should look like this:

SettingsSettings

Finally, you need to manually tell the settings file to generate itself by right-clicking, and selecting “Run Custom Tool”.

Conclusion and Caveat

One of the reasons that this is a bad idea is the last step. Although you are linking to the settings file, you need to manually generate each time.

So, it’s not a good way to do things, but if you need it, it does work.



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2024