Configuration.Properties 对象在 Visual Studio 2017 VSIX 扩展中返回 null

Configuration.Properties object returning null in Visual Studio 2017 VSIX extension

我使用 VSIX 项目模板为 Visual Studio 2015 构建了一个扩展。当您右键单击解决方案资源管理器中的项目时,它会在上下文菜单中添加一个按钮。当您单击此按钮时,它会更改该项目的一些调试设置,以便它可以进行调试。

但是,我还需要使其与 Visual Studio 2017 兼容。就菜单中出现的按钮而言,一切似乎都正常。我使用 dte2 对象获取当前选定的项目,然后使用它来获取选定的项目。从中我获得了活动配置并使用它来更改项目的属性。

在我获得配置对象之前一切正常。我可以获取对象,但是当我尝试获取 configuration.properties 时,它 returns 返回 null。

DTE2 dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE));
SelectedItem selectedItem = dte2.SelectedItems.Item(1);
Project project = selectedItem.Project;

Configuration configuration = project.ConfigurationManager.ActiveConfiguration;
string path = configuration.Properties.Item("OutputPath").value.ToString();

一切正常,直到我尝试从配置中获取属性。它 returns null,所以我在使用 .Item() 时遇到错误。

同样的代码在 Visual Studio 2015 年对我有效,但在 Visual Studio 2017 年无效。有人知道解决方案或解决方法吗?

This 是我经过大量 google 研究后发现的唯一相关 link。但这里 visual studio 团队的唯一回应是他们没有足够的信息。

编辑: 这就是我最终为我工作的:

DTE2 dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE));
SelectedItem selectedItem = dte2.SelectedItems.Item(1);
Project project = selectedItem.Project;

VCProject vcproj = project.Object as VCProject;
VCConfiguration vcconfig = vcproj.ActiveConfiguration;
VCDebugSettings vcdebug = vcconfig.DebugSettings as VCDebugSettings;

然后VCDebugSettings 对象可以编辑项目的调试属性。可以找到可用的属性 here

Does anyone know any solutions or work arounds to this?

如果你的项目是c++项目,可以使用VCProject获取配置对象。像这样:

 private void GetProjectProperties(object sender, EventArgs e)
        {
            DTE2 dte = (DTE2)Package.GetGlobalService(typeof(SDTE));
            VCProject prj = dte.Solution.Projects.Item(1).Object as VCProject;
            foreach (VCConfiguration vccon in prj.Configurations)
            {
                IVCRulePropertyStorage generalRule = vccon.Rules.Item("ConfigurationGeneral");

                string outputPath = vccon.OutputDirectory;

                vccon.OutputDirectory = "$(test)";
                //string test1 = generalRule.GetEvaluatedPropertyValue(2);
                string tar = generalRule.GetEvaluatedPropertyValue("TargetExt");
                string name = generalRule.GetEvaluatedPropertyValue("TargetName");
            }
}