You probably know about the “Add as Link” feature in Visual Studio. When adding an existing file to a project, you can choose “Add as Link” in the drop down and the file stays in the original location instead of being copied to the new project folder.
When you add an existing file to a project, the default option is to copy the file to the folder where your current project resides. If you want to instead link to the file (rather than actually moving the file to that folder) you can do so by choosing Add as Link… –MSDN
Linking to another folder
But what if you want to link to the the entire contents of a folder and have all the files available in the new project? You could add the files one at a time, but that is tedious. Instead you can add wildcards to the csproj/vbprog file and get all the files added automatically.
To get the correct XML in the csproj file I start by adding a link to a single file that is in the desired source directory. Once that is done, I open up the csproj file and find the link to the file.
Then change the XML as follows.
The first line (Compile) indicates the source directory. The wildcards work as you expect, *.* indicates that we want all the files. Note that it is a relative path from your current project.
The second line (Link) instructs MSBuild to add links to the files found in the source directory. %(RecursiveDir ) means to walk any children directories when linking the files. %(FileName) means to use the existing file name, and %(Extension) means to use the existing file extension. Here’s a link to the MSDN docs explaining the % tokens.
Note: Visual Studio does not automatically refresh the file list when a file is added, renamed or deleted from the linked folder while the project is open. The project needs to be reopened for the changes to appear.