Copy projects from existing VisualStudioWorkspace to new AdhocWorkspace

103 Views Asked by At

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
   }
}
0

There are 0 best solutions below