0

We have a VisualStudioWorkspace with all the projects that are open in Visual Studio. Now we would like to create a new AdhocWorkspace object, with a limited set of the projects in the VisualStudioWorkspace.

Is it somehow possible to copy projects from the existing VisualStudioWorkspace to the new AdhocWorkspace? At first sight it's only possible to add new empty projects (using adhocWorkspace.AddProject()).

foreach (var p in vsWorkspace.CurrentSolution.Projects)
{
   if (condition)
   {
      adhocWorkspace.AddProject(p);
      ^ doesn't work, p must be of type ProjectInfo, instead of Project
   }
}
TWT
  • 2,511
  • 1
  • 23
  • 37
  • Could you please share a minimal, reproducible sample with us? As a suggestion, please reference the [dte interface](https://learn.microsoft.com/en-us/dotnet/api/envdte.dte?view=visualstudiosdk-2017&viewFallbackFrom=visualstudiosdk-2019) and use `Solution p in vsWorkspace.CurrentSolution.Projects`. – Mr Qian Feb 19 '20 at 15:06
  • Hi Perry, thanks for your answer, but my OP already contains a sample piece of code of what I would like to achieve. – TWT Feb 21 '20 at 13:25

0 Answers0