How to Add As Link in Visual Studio
There may be times when you need to share source between projects but you can’t reference a dll. This would happen if you are writing multiple single file executables and you wanted to share source between them. By definition, a single file executable doesn’t reference a dll or it would not be a single file.
You can still share source using Visual Studio’s Add As Link feature.
To use Add As Link in Visual Studio, follow these steps.
- Right-click on your project in Solution Explorer and choose Add | Existing Item.
- Next navigate to your shared file and click to highlight the file.
- Next click the drop down arrow next to Add and choose Add As Link.
- Verify that the file was added as a link. You can tell because it has a different icon to distinguish it from other source files.
- Verify that the Build Action is set to Compile. It should be as this is the default Build Action for a .cs file.
You can now share source without using a dll.