首页 > 解决方案 > 使用 DTE,阅读 .NET 标准项目,配置管理器属性属性值抛出

问题描述

我的项目是 Visual Studio 2019 中的 VSIX 项目。

我正在使用 DTE2 读取每个构建配置,然后检查 NoWarn 属性的值。

对于诸如 WPF 项目之类的 .NET 项目,以下代码可以完美运行。

对于 .NET Standard 项目,它在尝试读取 nownarnProperty.Value 时崩溃。

foreach (Configuration configuration in project.ConfigurationManager) {
    Properties configurationProperties = configuration.Properties;
    Property nowarnProperty = configurationProperties.Item("NoWarn");
    var value = nowarnProperty.Value;
}

.NET Standard 项目在尝试读取值时抛出:

StackTrace - nowarnProperty.Value 'nowarnProperty.Value' 引发了类型为 'System.Runtime.InteropServices.COMException' 对象 {System.Runtime.InteropServices.COMException} 的异常

问题

非常感谢您,

卡尔

标签: c#envdteconfigurationmanager

解决方案


推荐阅读