Adding linked items to projects

One little tip before I leave town.  A very useful but well-hidden feature is
that of "linked files" within a VB or C# project.  This lets you point to
a file without having it be copied into the same directory of your project. 
You still get syntax coloring, intellisense, etc.  Here's an example of how to
do this for a C# WinForms app using VS 2003 (but it should work the same in VS 2002).

Create a C# WinForms application project, e.g. named WindowsApplication1.  Now
do Project.Add Existing Item (or hit ctrl+D, or right-click on the project node and
do Add / Add Existing Item).  Find the file you want to link to -- a .cs
file in some other directory -- BUT DON'T hit the Open button yet!!!  Click
the little down-arrow to the right of the Open button and a little menu will pop up. 
Pick the bottom entry, "Link File", and click on it.

Boom!  The file you chose is now part of your project, and its icon in the
solution explorer is now a little different than the others -- it has a little arrow
pointer to indicate that it's a linked file and not sucked into the project directory
like the others.

Off I go on vacation -- have a great 4th! -Chris

Comments (4)

  1. Dmitriy Zaslavskiy says:

    Welcome and thanks for the tip.

  2. Blair Stephenson says:

    Yep we use it, but the VSS integration sucks. (This is only when the file is in a directory above I think). VS.Net bascially says the file exists outside the project and ignores it for VSS.

  3. Too bad it isn’t available for ASP.NET projects. Yet another reason it seems like creating them as library projects (while tedious) makes more sense.

  4. Chris Flaat says:

    Regarding putting linked items under source control, see my entry from today for a brief discussion of this.

Skip to main content