如何删除 VS 扩展中的解决方案文件夹和内容?

How do you delete Solution Folder and contents within a VS extension?

我正在为 VS 2017 编写 VS 扩展,需要从解决方案中删除解决方案文件夹及其内容。除了使用 ProjectItem.Remove 从项目中删除项目和使用 Project.Delete 从解决方案中删除项目之外,我找不到太多文档。但是,调用这些方法中的每一个都会导致以下异常:

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

在扩展程序中删除解决方案文件夹的正确方法是什么?

Solution Folder 是给定解决方案中的一个项目,与任何其他项目一样。

要从解决方案中删除项目,您不能调用 proj.Delete(),即 not implemented as per official documentation:

Removes the project from the current solution.

Note that this method is not currently implemented.

相反,您必须使用 dte.Solution.Remove(proj);,这也适用于解决方案文件夹。