Use Project Linker to share source code across multiple projects
About Enhanced Add-ins
First, there is a note about the add-in before the how-to instructions.
I'm using an extension add-in to Visual Studio 2012, Project Linker 2012, but there's also Project Linker, which has almost the same functionality, but with different authors, and Project Linker only works fine in Visual Studio 2010. This time, the add-in used in Visual Studio 2012 will be "Project Linker 2012".
Conversely, if you are using Visual Studio 2010, you can include "Project Linker". I think that you can set it in almost the same way as what I will explain this time.
About sharing source code between multiple projects
Sharing source code between multiple projects itself is standard in Visual Studio. Since the source files basically need to be placed below the folder where the project files are located, for example, if you drag the source files of project A to project B, it will be a copy of the file, which will be double management of code.
Let's start with the ability to share source code in Visual Studio. To put it simply, it is an image that creates a link (shortcut) of the source file. To create a code link, complete the following steps:
We have created projects called Application1 and Application2, where the source files are actually in Application1 and Application2 references the source files. In the figure below, we have a "ProfileLoader.cs" file in Application1 that the Application2 project references.
Right-click the Application2 project and choose Add > Existing Item.
When the file selection dialog is displayed, select the "ProfileLoader.cs" file in the folder of "Application1" from which you are referring, click the "▼" button to the right of the bottom right, and select "Add as link".
The ProfileLoader .cs file is added to the project in Application2. This is just a link to the Apllication1 ProfileLoader.cs file, not a copy. You can see that the square and arrow icons have been added at the bottom right of the file icon.
If you open and edit the ProfileLoader.cs file in Application2 in this state, you are editing the ProfileLoader.cs file in Application1.
Of course, the referenced file is done in the same way as when you put the source file normally. Since the namespace remains Application1, you can use the class as usual by specifying the namespace as shown below.
Use Project Linker to automate source code sharing
If you only have two projects sharing source files, or if you only have a few files to share, as mentioned above, there is no problem with manual operation, but if you have more projects or files, manual work can be quite a hassle. Since the number of files that can be shared at one time by the above operation is one folder unit, the same procedure must be followed if the folders are hierarchical. Also, if you want to change the folder hierarchy, you must reconfigure it in all projects.
You can automate these operations using the following Visual Studio extension, Project Linker. Note that extensions are only available in Visual Studio editions of Professional or higher.
Download from the following URL:
Once you have downloaded the file, double-click it to launch it. It is in installer format. Close all Visual Studio before installing.
Make sure that the Visual Studio you want to install is checked and click the Install button.
Close it after successful installation.
When the installation is complete, open the solution file with multiple projects. In this case, suppose that the project "Application1" has the substance of the source file and "Application2" has its reference.
Right-click the project you want to reference and choose Add project link.
When a dialog opens, select the referrer for the Applicarion1 project. As the title says "Select Source Project", select the project that has the source file entity. Once selected, click the OK button.
When "Link all items by default" is checked, when you press the "OK" button, the files and folder structure of Application1 will be synchronized to Application2, so if you do not want to synchronize suddenly, please uncheck it. Conversely, if you want to synchronize in bulk, it is convenient to check.
If the link is successful, click the "OK" button.
Application2 is linked to Application1, so let's try adding a class to Apllication1. Once you have created a link for your project, you basically perform the operation with the reference source "Application1".
Right-click the project and choose Add - New Item.
Add a class. Classes can add whatever they want. Here we are creating a class called "StringHelper" to assist in string editing.
When you add a source file, a link is automatically created for the file in the Application2 project.
Try creating a folder.
The folder is also created automatically. By the way, there is no concept of a link in a folder, so what is created is a physical folder.
If you move the file to the folder you just created, the linked destination will also be automatically moved in the same way.
Try deleting the folder and the files in it.
The link will be removed in the same way. In this way, Project Linker allows you to synchronize file and folder structures across multiple projects.
When you have multiple linked projects, you can check what state they are currently in. From the menu, select Edit project links.
Here you can review the list of links and unlink them. To unlink, select the target link from the list and click the "Unlink" button.