If you’re like most developers, you probably work on multiple projects at the same time. You might have a project for your own use, and another project that you’re working on for a client. Maybe you’re also working on a project for school. One way to share files and code between projects is to use the File Share feature in Visual Studio. This article will show you how to do it. First, open Visual Studio and create a new project. In the New Project dialog box, select File Share from the Templates category. The File Share dialog box will appear. In the File Share dialog box, select the folder where you want to share files and code between your projects. Then, click OK. Now, in your new project, open the file that you want to share with your other projects. In this example, we’ll open MainWindow.xaml in our new project’s MainWindow folder. Notice that when we do this, Visual Studio opens up a copy of MainWindow.xaml in our shared folder (in this case C:\Users\username\Documents\Visual Studio Projects\SharedFiles). ..
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.