3

I have 31 projects, each is inside a folder and i have an empty visual studio solution, is there a way to add all projects in the folder to my solution without having to add them one by one?

FPGA
  • 3,525
  • 10
  • 44
  • 73
  • 1
    Try [this](http://stackoverflow.com/questions/747687/how-to-automatically-add-a-huge-set-of-vcproj-files-to-the-solution) – Millie Smith Oct 13 '13 at 06:25
  • This one did it too http://stackoverflow.com/questions/1891035/easy-way-to-add-multiple-existing-csproj-to-a-visual-studio-solution – FPGA Oct 13 '13 at 06:40

1 Answers1

15

Assuming you have NuGet installed, you can do this via the Package Manager Console (Tools :: Library Package Manager :: Package Manager Console) using the following:

$sln = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
Get-ChildItem -Recurse *.csproj | %{ $sln.AddFromFile($_.FullName) }

Replace csproj with vbproj if you are using VB.NET.

Edit To clarify: as Dave points out, the reason this is possible via a seemingly unrelated tool is that the PMC exposes a Powershell interface with support for the Visual Studio APIs already configured, making it the simplest way to "script" against the IDE.

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
  • You might want to mention why a "package manager" has commands like that. – John Saunders Oct 13 '13 at 07:36
  • @JohnSaunders because NuGet is powershell based – FPGA Oct 13 '13 at 08:55
  • @user1492051 yes, "PowerShell" was the magic word, but it would still be better for future readers if Richard edited his answer to say so. Then they wouldn't need to read our comments. – John Saunders Oct 13 '13 at 09:28
  • In Visual Studio 2017 (and 2015 I think) the console can be opened from `Tools > NuGet Package Manager > Package Manager Console` – AlexanderD Jul 12 '18 at 09:16