This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Visual Studio
VS 2003+

Visual Studio Sharing Files Between Projects

Normally when an existing file is added to a project within Visual Studio, the file is copied into the project folder. There is an option to link to the file, rather than duplicate it, allowing files to be shared between multiple projects.

Adding Existing Files to a Project

When you are creating a project using Visual Studio you can create and add new files or include files that already exist. When you add an existing file using the default options, the file is copied from the original location into the target directory within the project folder. All further editing is of the new copy and is not reflected in the original file.

Another option is to link to the existing file instead of duplicating it. Using this option you can share files between multiple projects, either in the same solution or separate solutions. As only one file exists, editing it is reflected in all projects that use it. This can be particularly useful if you have utility classes that are not complex enough to warrant compiling into an assembly, or if you have a configuration file that you wish to share amongst all projects in a solution.

To link to an existing file, right-click the target location in the Solution Explorer and choose "Add" and then "Existing Item", as though you were copying in an existing file. Choose the file that you wish to add by clicking it once. At this point you would normally click the Add button. Instead, click the small drop-down arrow at the side of the button and choose "Add as Link". You should see that the file is included in the project and is shown with a shortcut symbol overlay on its icon to indicate a linked file.

Visual Studio Add Linked File

NB: If you are using Visual Studio 2003, select "Add Existing Item" from the shortcut menu that is displayed when you right-click in the Solution Explorer. The option to select from the Open button drop-down is "Link File".

24 November 2010