gpt4 book ai didi

c# - EnvDTE 遍历解决方案中的子文件夹

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:02 25 4
gpt4 key购买 nike

在 VS 解决方案中有以下结构:

现在,我想获取对“Catalogs”文件夹的引用并将其存储在变量中:

        //Solution_Name
// ConfigurationObjects
// Catalogs
// Documents

foreach (Project item1 in AttachedSolution.Projects)
{
if (item1.Kind == ProjectKinds.vsProjectKindSolutionFolder)
{
if (item1.Name == "ConfigurationObjects")
{
SolutionFolder catalogBaseFolder = (SolutionFolder)item1.Object;

foreach (ProjectItem item2 in item1.ProjectItems)
{
if ( item2.Name == "Catalogs")
{
this.CatalogObjectsFolder = (SolutionFolder)item2;
// raises error here: Unable to cast COM object of type
//'System.__ComObject'
//to interface type 'EnvDTE80.SolutionFolder'.
};
};
};
};
};

感谢您的帮助。

最佳答案

非第一级的解决方案文件夹建模为 EnvDTE.Project,而不是 EnvDTE80.SolutionFolder。您可以使用 projectItem.SubProject 属性从 projectItem 获取项目。然后使用 Project.Object 获取 EnvDTE80.SolutionFolder

参见:

HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in

How to create a solution folder inside another solution folder

关于c# - EnvDTE 遍历解决方案中的子文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30767129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com