Click here to Skip to main content
15,894,405 members
Articles / Visual Studio / Visual Studio 2010

Linked Files in Visual Studio 2010

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
13 Jun 2011CPOL2 min read 34.9K   2   8
File Linking, File Sharing and Shared Projects

You know how it feels to have shared files on VSS?

Gooood.
Actually it felt so good that my beloved CTO (who said something about promotion?) switched to TFS just 4-5 months ago. And ever since - I cry myself to sleep every night.

Instead of one file, shared between 5, 6, 7 or 10 projects, we now have a copied file for each project. This is due to Microsoft "Best Practice" which says - No Shared Files.

Meaning...?

If I have a JavaScript file called Arrays.js. It's all purpose is to handle arrays in JavaScript. This file exists in 6 different projects, which means that if I have another addition to this small JavaScript library, I have to copy it to 6 different files in 6 different projects...

JUST SHOOT ME!!!

Finally, I have the fix we've all been waiting for, courtesy of VS 2010: "Add File As Link".

How to Link Files to Different Projects

Let’s say we have 2 completely different web sites - one is 10Bet and the other is SportsBettingTech.

I will usually place the original file inside the main project, in this case - 10Bet. I click on the project's name -> Add -> New Item...

A dialog box will open.

I will choose a JavaScript file. Just for testing. We will call it: "LinkedFile.js". I will place a small comment in this file, and Check In.

Now I will go to my second project. Click on the project's name -> Add -> Existing File...

A dialog box will open.

Go to the file you'd like to link to (Hint: It's in a different project's folder), choose it, and instead of clicking the "Add" button, click on that small arrow to the left.

Choose "Add As Link".

And you're done.

How File Linking Works

The point of file linking is that you have one file. This file physically exists in one place (the project it was created in) but has virtual copy of it wherever you want.

If you choose to change this file from the mother project -> after you check in -> you will be able to see the changes wherever you linked it to.

The Million Dollar Question:
"What happens if I change the file from elsewhere?"

That's a great question.

And the answer is: With a very (very) simple solution.

The original copy of the file is being checked out. You will still be your secondary website's solution, but this file will automatically be checked out and displayed on your Visual Studio.

After you change it, simply check in and that's it.

Lots of luck and happiness and good night sleep.

Elad,

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
QuestionFinding where a linked file is used Pin
JBIRD209319-Mar-14 4:32
JBIRD209319-Mar-14 4:32 
QuestionWhat about master page Pin
Dnyaneshwar Pawar22-Nov-12 1:14
Dnyaneshwar Pawar22-Nov-12 1:14 
QuestionThere is no "Add link" possibility in native c++ project? Pin
Member 5508749-Apr-12 1:43
Member 5508749-Apr-12 1:43 
QuestionThere is no add file as a link in a web-site project? Pin
Diing4-Jul-11 13:54
Diing4-Jul-11 13:54 
AnswerRe: There is no add file as a link in a web-site project? Pin
DevAffair4-Jul-11 19:55
DevAffair4-Jul-11 19:55 
GeneralRe: There is no add file as a link in a web-site project? Pin
Diing4-Jul-11 21:21
Diing4-Jul-11 21:21 
GeneralRe: There is no add file as a link in a web-site project? Pin
DevAffair4-Jul-11 21:54
DevAffair4-Jul-11 21:54 
GeneralMy vote of 5 Pin
Francis Judge21-Jun-11 3:12
Francis Judge21-Jun-11 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.