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.

  1. Right-click on your project in Solution Explorer and choose Add | Existing Item.
    Visual Studio Add Existing Item
  2. Next navigate to your shared file and click to highlight the file.
  3. Next click the drop down arrow next to Add and choose Add As Link.
    Visual Studio Add As link
  4. 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.Icon for Add As Link Source
  5. Verify that the Build Action is set to Compile. It should be as this is the default Build Action for a .cs file.
    Visual Studio Build Action Compile

You can now share source without using a dll.

Leave a Reply

How to post code in comments?