views:

119

answers:

2

Keeping properties of multiple Visual Studio projects manually in sync is annoying. So, how can you share properties between multiple projects?

Edit: I refer to properties like conditional compilation symbols, treatment of warnings and errors etc., i.e., things you can configure in Project->Properties tabs or by editing the project XML file.

Similar questions have been asked before, see: 1, 2 and 3. However, in my understanding, the answers have been C++-specific. I am looking for an answer for C# projects. Nevertheless, do not hesitate to answer for other kinds of projects (Visual Basic etc.) if you keep the separation clear, because someone else than me might be interested.

This blog post proposes a solution to the problem, but I would prefer something simpler.

Also, you can at least solve a part of the problem in the following way (note that although I tested it, I did not test it thoroughly):

Create an AssemblyInfo.cs file with the assembly attributes you intend to share. Link to this existing item in the individual projects. Use the original (local) AssemblyInfo.cs and put project-specific assembly attributes there. Unfortunately, overriding attributes does not seem to work, and managing the attributes via the GUI is now limited.

+1  A: 

For that kind of things, I prefer to have a separate Class Library Project, with one (or more) static classes storing the (static) properties. Then add a reference to that project from every project that needs to have those properties in sync, and all those projects will have the same values and you have to change it in only one place.

For example, let's say that I have the same app in web and desktop form. Things like connection strings and such will have to be the same for both. So I will create three projects:
MyProject.Web (Web application)
MyProject.Desktop (Windows forms application)
MyProject.Common (Class library)
Then I add a new static class in Common called Properties with a static property called ConnectionString that returns the connection string.
I then add a reference to Common in Web and Desktop, and when I want to access the connection string from any of them I use Common.Properties.ConnectionString.

Yandros
Thanks. However, my intention when speaking of properties has been to refer to the build configuration rather than the runtime configuration. I.e., things you can configure in Project->Properties->Application, Project->Properties->Build etc.
Marco
I see. I'm afraid that I can't propose anything better than what you posted yourself. Sorry I couldn't be of help.
Yandros
A: 

We make very heavy use of the .vsprops files to have shared macros defined between our native projects.

Someone asking exactly the same question as you came up with the idea of adding a "blank" visual C++ project to the solution so that could import the vsprops file and the properties would be generally visible to the rest of the solution. If it doesn't sound too gross a hack, I can find out how it worked out.

Andy Dent