(…or from project to project in another solution!)
I do a fair bit of spiking before I get into the thick of things with code (anyone who’s worked closely with me has seen my endless projects in my Spike directory).
It can be frustrating if you’ve got a collection of small classes that you’d like to copy from one of your spikes to a new project/solution to start unit testing. Visual Studio does not allow you to copy from the solution explorer, switch to the other Visual Studio instance, and then paste the files. Instead, you get the following error:
The source files for this operation cannot be found in this solution.
Start in the solution with the files you want to copy. Right-click on the containing folder (or the project) and click Open Folder in Windows Explorer.
Next, using Windows Explorer, select the files that you want to copy and put them on the clipboard.
Flip over to your target solution, and find the project or folder that you want to put the files into. Use the same right-click trick to open the folder location on the hard drive. Now, paste the files into this directory in Windows Explorer.
Lastly, return to your target solution; here, we have to let Visual Studio know that these files are part of your project. Even though they are in the project folder, they won’t be included and can’t be referenced until you express your interest in doing so. Select the target directory and click on the Show All Files icon in the toolbar for Solution Explorer. Your new files will now appear in the project, but they will have a different icon. Select them all (use shift-selecting or ctrl-selecting if you need to) and right-click to reveal this menu:
Click on Include in Project and you’re set. Now you can move classes and resources from one project to another using Visual Studio (and Windows Explorer).