【问题标题】:Modifying project properties of custom project system in VisualStudio在 Visual Studio 中修改自定义项目系统的项目属性
【发布时间】:2015-02-16 05:04:43
【问题描述】:

我尝试通过遍历https://msdn.microsoft.com/en-us/library/vstudio/cc512961.aspx 来创建自定义项目系统并成功。现在我想修改这个创建的项目系统的项目属性。本演练的第二部分是指导为解决方案属性创建属性页。 (解决方案资源管理器-> 右键单击​​解决方案并选择属性)我不想修改解决方案属性,我需要通过添加新选项卡和其他项目来自定义项目属性(解决方案资源管理器-> 右键单击​​项目并选择属性)我的自定义项目系统。请尽快帮助我...

【问题讨论】:

    标签: visual-studio visual-studio-extensions vsix vsx vspackage


    【解决方案1】:

    如果您的项目系统基于MPF,则可以通过ProjectNode 类集成自定义标签页。这个类定义了GetConfigurationIndependentPropertyPagesGetConfigurationDependentPropertyPages方法;这些是虚拟方法,可以由任何派生类型实现,以返回 IPropertyPage 实现的类型 ID。

    internal class CustomProjectNode : ProjectNode
    {
        protected override Guid[] GetConfigurationIndependentPropertyPages()
        {
            return new[] 
            {
                typeof(MyCustomPropertyPage).Guid
            };
        }
    }
    

    IPropertyPage 接口是项目系统和允许更改属性的 UI 之间的连接器,其中 UI 是一个普通的窗口(通常是 Windows 窗体Control)。属性页实现必须使用ComVisible- 和ClassInterface-attributes 进行标记,如果想要保持对type-guid 的控制,还可以选择使用Guid-attribute。

    [ComVisible(true)]
    [Guid("...")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    internal class MyCustomPropertyPage : IPropertyPage
    {
        ...
    }
    

    此外,属性页类型必须通过包类上的ProvideObject-attribute 公开。

    [ProvideObject(typeof(MyCustomPropertyPage))]
    class MyPackage : Package
    {
    }
    

    最后,要使属性页显示为选项卡,自定义项目节点的SupportsProjectDesigner 属性必须设置为true

    internal class CustomProjectNode : ProjectNode
    {
        public CustomProjectNode() 
        {
            this.SupportsProjectDesigner = true;
        }
    }
    

    【讨论】:

    • 您好 Matze,非常感谢您的更新。除了最后一步,我已经做了以上所有的事情。我无法将 SupportsProjectDesigner 设置为 true。我必须在哪个类中使用此代码。请给我一个解决方案。提前致谢。
    • @MathivananKP 这是一个由ProjectNode 类定义的虚拟属性。您可以在这里找到它:mpfproj12.codeplex.com/SourceControl/latest#Dev12/Src/CSharp/… 因此,只需从该类型派生您的项目节点 - 代码(如上所示)应该可以工作......顺便说一句,如果解决方案适合您,请接受答案(-;
    猜你喜欢
    • 1970-01-01
    • 2012-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 2013-07-11
    • 2021-08-03
    相关资源
    最近更新 更多