66

In Visual Studio there is a way to have a file in another project that is a shortcut to the first so that it builds in both. How do I do that?

Matthew Kruskamp
  • 1,887
  • 2
  • 14
  • 31
  • I found [a different solution](https://stackoverflow.com/a/12858818/31532) as the accepted answer doesn't work for me in VS2019. – Dan Atkinson Apr 29 '21 at 14:38

3 Answers3

127

Right-click the project, select Add > Existing Item, and in the dialog drop down the Add button and select Add As Link.

Add As Link

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
itowlson
  • 73,686
  • 17
  • 161
  • 157
  • 3
    Although I up-voted the solution itowlson posted, as that was what I was trying to do and what I think the poster was asking, it's worth considering the alternative to this, if possible, which is to include the project that holds the file as a reference (using the Add Reference dialog, and the Project tab within that). Then put a using statement in your file (if c#), and use that namespace direct. R – Retne Dec 08 '09 at 14:40
  • 2
    Mendy: are you sure? I'm using this exact technique on a VS2010 project at the moment, so it's definitely working for me. – itowlson Apr 23 '10 at 19:24
  • it's perfectly working solution. when you have the same classes to be used in Silverlight and .NET, you could just create a silverlight project assembly with the files in it and then create a .net project with links to the files in silverlight project. code reuse at its best. – pencilslate Sep 28 '10 at 21:44
  • You save my life for looking around creating a soft link some more I'm working on my local thumbdrive yet it is a fat32 format not NTFS which fat32 not support symbolic link in Windows though. – yancyn Mar 02 '12 at 03:22
1

This is not a direct answer but an alternative that may be worth considering in some cases.

You can create a specific kind of project which can "include" a set of files in another project when it is added by reference. This is called a Shared Project which is one of the 'new project' options:

enter image description here

(Since at least Visual Studio 2015 - maybe earlier).

One advantage of this type of project over individual shortcuts is that it includes a set of things as a bundle. So if you have a large # of items, this may be easier and less error prone.

Also it uses the familiar "reference" metahphor in the context of the solution and in that way functions quite similarly to other project references; the difference is that in a shared project the items in the project are added into each referring project, but in a normal project the assemblies (DLLs) end up owning the reference at runtime. Shortcuts may be less familiar to other developers than the reference pattern.

More information: What is the difference between a Shared Project and a Class Library in Visual Studio 2015?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
-3

Are you talking about a solution with multiple projects? In that case answer would be using Project Dependencies (within Project menu).

Szere Dyeri
  • 14,916
  • 11
  • 39
  • 42