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.
- › What’s New in Windows 11’s 22H2 Update: Top 10 New Features
- › The 10 Best Netflix Original Movies in 2022
- › NZXT Signal 4K30 Capture Card Review: Lossless High-Quality Footage
- › “Atari Was Very, Very Hard” Nolan Bushnell on Atari, 50 Years Later
- › A World Without Wires: 25 Years of Wi-Fi
- › T-Mobile Is Selling Your App Activity: Here’s How to Opt Out