32

What I usually do is create a new file in the solution where I want to use it (same name), copy & paste the contents of a class from the source solution to the target, fix the namespace & imports as needed.

The only other way I know to do it is open the source file in the target solution and then just save a copy into that folder, which can get confusing with two files open with the same name in one solution.

Does anyone have an easier way to do this?

informatik01
  • 16,038
  • 10
  • 74
  • 104
Berryl
  • 12,471
  • 22
  • 98
  • 182

2 Answers2

43

You can just copy and paste the files themselves.

When you have your solution open, look at the top of the solution explorer and you'll see an icon that looks like a page with a page outline behind it and a yellow page (not a very intuitive icon). This is the "show all files" button. Click that and you'll see all the files in your currently selected project (it is project-specific). Highlight any files that you want to include, right-click, and select "Include in Project."

enter image description here

Jay
  • 56,361
  • 10
  • 99
  • 123
  • I don't see the "show all files" button on Visual Studio 2017. – Saulo Silva Nov 27 '19 at 14:34
  • 1
    @SauloSilva I still see it in VS2019, so I have to imagine it was there in 2017 as well. It doesn't quite look the same, but still shows multiple pages and the hover tooltip still says "Show All Files." – Jay Dec 02 '19 at 20:23
  • @Jay Found it. I had to select a project for it to show up. Thanks! – Saulo Silva Dec 03 '19 at 18:08
6

You could just copy the file with Explorer. Or better yet, start refactoring your projects so that you'll create assemblies that are usable by multiple client projects.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • agreed. i commented on your last answer about assembly names to see you you had any approaches to refactoring assemblies. I don't know of a Resharper or other offering that does this painlessly. – Berryl Feb 03 '10 at 04:26
  • 4
    Right, the tool you need for that is the one between your ears. – Hans Passant Feb 03 '10 at 05:07
  • Yeah, I do tend to forget that one is sometimes available :-) – Berryl Feb 04 '10 at 05:46