1

I'm writing a VS Extension for VS 2017, and need to remove a Solution Folder and its contents from the solution. I have been unable to find much documentation aside from using ProjectItem.Remove to remove items from a project and Project.Delete to remove a project from the solution. However, calling each of these methods results in the following exception:

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

What is the proper way to delete Solution Folders in an extension?

M Reza
  • 18,350
  • 14
  • 66
  • 71
Glen Hughes
  • 4,712
  • 2
  • 20
  • 25
  • Are you looking for this `IVsSolution7.CloseFolder` ? https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivssolution7.closefolder?view=visualstudiosdk-2017 – Simon Mourier Jan 30 '19 at 07:41
  • That method is similar to closing a solution; it doesn't actually change a solution or project. I'm looking for a way to remove a Solution Folder and its files from a solution, which would in effect modify the sln file to remove the appropriate nodes. – Glen Hughes Jan 30 '19 at 22:31
  • Sorry I mixed up different concepts. A "solution folder" is a project like the others, but `proj.Delete()` doesn't work (as per documentation https://learn.microsoft.com/en-us/dotnet/api/envdte.project.delete). You must use `dte.Solution.Remove(proj)` – Simon Mourier Jan 31 '19 at 08:59
  • Thanks, that's exactly what I was looking for. Would you provide this as an answer so I can mark it as correct? – Glen Hughes Jan 31 '19 at 16:16

1 Answers1

0

A Solution Folder is a project in a given solution like any other project.

To remove a project from a solution, you cannot call proj.Delete() which is not implemented as per official documentation:

Removes the project from the current solution.

Note that this method is not currently implemented.

Instead, you must must use dte.Solution.Remove(proj); and that should work for solution folders as well.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298