Thursday, July 19, 2007

Sharing a file between Multiple Projects in VB.NET or C#

It was difficult for me to figure this problem out without some help. If you want a .vb or .cs file (or any other file) shared between multiple projects in Visual Studio, the normal thing to do is to right click on the project in the Solution Explorer, select Add, then select Existing Item, and pick the file from project 1 that you want to share with project 2. This unfortunately makes a copy of the file and you now have two different versions of the file to maintain. However, the Add button on the Exiting Item's dialog has a innocuous drop down arrow. If you drop down the menu, you can choose Add as Link, which does not copy the file.




Here is a rambling discussion on this topic, but the is solution they come to is described above:




7 comments:

Anonymous said...

Thanks. I've been wanting to do this for weeks. Never noticed that before.

Anonymous said...

Great find. It's exactly what I needed.

paddy said...

Thanks. Another triumph of Google searching over Microsoft's 'help' systems!!

Anonymous said...

Thank you

oskarh6666 said...

Even in 2010 I found what I wanted. Thanks to Google and specially to srego.

Although I did the same "by hand" I mean opening the .vbproj file and changing the relative path for file.

Your solution is easier.

Anonymous said...

Thanks !! Still useful even after 4 years !
Richard

Anonymous said...

Awesome! I have been wanting to do this for quite some time.