Wednesday, August 21, 2019

Add a Linked File in a Visual Studio Project: Add As Link


Yesterday I had to add a file into a database project as a link to another file. So not a copy of the file, but a link so I can use the file in multiple database projects and only have to maintain it once. Because I couldn't easily find the solution to this and I was searching on Google but also couldn't find it quick (enough to my opinion :)), I decided to write a short blog post.
I didn't know the exact naming of the property, so the majority of the links I got from Google where Linked Server items, only after changing the search phrase 3 or 4 times I found this entry by Grant Winney.

The normal icon that appears when you add a file is the following (at least when you don't have changes in source control, here TFS). A little blue lock is displayed, letting you know that it is a local file and it is checked-in in source control.






The other available icons would be:
A plus sign for a newly added file, not yet in source control:






A red check mark, for a changed file already in source control.

TL;DR - Solution

The trick to add a file as a link is not in the menu options in Visual Studio itself, that's also where I started searching.
You have to first add an existing item to your desired folder, as shown below.








After selecting the file, don't click Add, but click the dropdown next to the Add button. There you can select Add As Link.











Et voilá, we've got ourselves a linked item, with the new icon that looks like a hyperlink :)







Let me know if you have any remarks and found this post useful in the comments!
Nicky

2 comments:

  1. how do I access the code in the class though?
    for example I have added a .cs file a linked item and I cannot access it from other classes in the project?

    ReplyDelete

Thanks for taking the time to provide feedback!

Cheers,
Nicky

Featured Post

Governance & Administration - Tenant Settings: Searching

With all the Fabric announcements in the last months, some of the Admin announcements might have slipped through. As you might know, the Adm...