Visual Studio “Solutions” are able to store multiple projects and assemblies. Usually, they’re fairly separate, but what if you need to share code among them? One of the simplest ways to do this properly is with symlinks.
Linking Files Across Projects
First, you should ask yourself if symlinks is really the best method to handle this. Sharing code between projects sounds like a great use case for just using an external class library. If you have that as an option, you should take it. Using symlinks would result in duplicate code in each assembly that references it. However, using an external class library usually comes with adding an extra DLL as a runtime dependency, which is a problem if you’re referencing a lot of code.
If it’s just a single class file you need to reference in multiple places, using symlinks will make it easier to manage. You won’t need to deal with the headache of copying files back and forth whenever you make changes. Each project will reference the same location on disk.
Doing this is very simple. In the target location, right click the folder and select “Add > Existing Item…”
Usually you’d just press “Add,” but in this case, you actually want to click the dropdown and select “Add As Link.”
That’s really all there is to it—the file should now be visible in both locations, and if you make changes to it from one place, it will reflect in the other. Really, there’s only one file there, but when the assembly builds, it will include it in both assemblies.