VS2019添加项目属性页

问题描述 投票:0回答:1

我正在尝试扩展VS2019项目属性页面并添加一个新页面,但是如果使用Microsoft指南,我将无法正常工作:

Adding and removing property pages

有人可能有示例代码吗?

编辑:

My Project

我目前有一个普通的VSIX项目,我曾用它来创建一个Editor包并成功添加了菜单项。我基本上只想添加一个项目属性页面,该页面将在所有“类库”项目中使用。

visual-studio-2019 visual-studio-extensions vsix vs-extensibility vsx
1个回答
0
投票

有人可能有示例代码吗?

实际上,遵循指导,您可以得到想要的东西。

遵循此指南:

删除属性页

1)在VS2019 IDE中创建一个vsix c#项目,然后添加一个新类,例如RemovePage

2),然后在这些文件中添加这些名称空间:

using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

并实现IVsHierarchy接口并添加其实现方法。

3)之后,在页面底部,添加主要功能以实现它:

protected int GetProperty(uint itemId, int propId, out object property)
        {
            //Use propId to filter configuration-independent property pages.
            switch (propId)
            {

                case (int)__VSHPROPID2.VSHPROPID_PropertyPagesCLSIDList:
                    {
                        //Get a semicolon-delimited list of clsids of the configuration-independent property pages


                        ErrorHandler.ThrowOnFailure(GetProperty(itemId, propId, out property));
                        string propertyPagesList = ((string)property).ToUpper(CultureInfo.InvariantCulture);
                        //Remove the property page here

                        string buildEventsPageGuid = "{1E78F8DB-6C07-4D61-A18F-7514010ABD56}";
                        int index = propertyPagesList.IndexOf(buildEventsPageGuid);
                        if (index != -1)
                        {
                            // GUIDs are separated by ';' so if you remove the last GUID, also remove the last ';'
                            int index2 = index + buildEventsPageGuid.Length + 1;
                            if (index2 >= propertyPagesList.Length)
                                propertyPagesList = propertyPagesList.Substring(0, index).TrimEnd(';');
                            else
                                propertyPagesList = propertyPagesList.Substring(0, index) + propertyPagesList.Substring(index2);


                        }
                        //New property value
                        property = propertyPagesList;

                        break; 
                    }

            }

[添加属性页

1)添加一个名为DeployPropertyPage的新类,并实现Form和Microsoft.VisualStudio.OLE.Interop.IPropertyPage。然后,根据提示添加实现方法。

2)添加这些名称空间:

using Microsoft.VisualStudio.OLE.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using MSVSIP = Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;

3)将默认功能GetPageInfo更改为:

 public void GetPageInfo(Microsoft.VisualStudio.OLE.Interop.PROPPAGEINFO[] pPageInfo)
        {
            PROPPAGEINFO info = new PROPPAGEINFO();
            info.cb = (uint)Marshal.SizeOf(typeof(PROPPAGEINFO));
            info.dwHelpContext = 0;
            info.pszDocString = null;
            info.pszHelpFile = null;
            info.pszTitle = "Deployment";  //Assign tab name
            info.SIZE.cx = this.Size.Width;
            info.SIZE.cy = this.Size.Height;
            if (pPageInfo != null && pPageInfo.Length > 0)
                pPageInfo[0] = info;
        }

4)将主要功能添加到文件底部所说的文档中:

protected int GetProperty(uint itemId, int propId, out object property)
        {
            //Use propId to filter configuration-dependent property pages.
            switch (propId)
            {

           case (int)__VSHPROPID2.VSHPROPID_CfgPropertyPagesCLSIDList:
            {
                //Get a semicolon-delimited list of clsids of the configuration-dependent property pages.
                ErrorHandler.ThrowOnFailure(GetProperty(itemId, propId, out property));
                //Add the Deployment property page.
                property += ';' + typeof(DeployPropertyPage).GUID.ToString("B");

                 break;
            }
        }

       return GetProperty(itemId, propId, out property);
    }

5)然后在类名称DeployPropertyPage之前注册您的新属性页。

[MSVSIP.ProvideObject(typeof(DeployPropertyPage), RegisterUsing = RegistrationMethod.CodeBase)]

更新1

DeployPropertyPage像这些:

class DeployPropertyPage:IPropertyPage
    {
        public void SetPageSite(IPropertyPageSite pPageSite)
        {
            throw new NotImplementedException();
        }

        public void Activate(IntPtr hWndParent, RECT[] pRect, int bModal)
        {
            throw new NotImplementedException();
        }

        public void Deactivate()
        {
            throw new NotImplementedException();
        }

        public void GetPageInfo(PROPPAGEINFO[] pPageInfo)
        {
            throw new NotImplementedException();
        }

        public void SetObjects(uint cObjects, object[] ppunk)
        {
            throw new NotImplementedException();
        }

        public void Show(uint nCmdShow)
        {
            throw new NotImplementedException();
        }

        public void Move(RECT[] pRect)
        {
            throw new NotImplementedException();
        }

        public int IsPageDirty()
        {
            throw new NotImplementedException();
        }

        public int Apply()
        {
            throw new NotImplementedException();
        }

        public void Help(string pszHelpDir)
        {
            throw new NotImplementedException();
        }

        public int TranslateAccelerator(MSG[] pMsg)
        {
            throw new NotImplementedException();
        }
    }

RemovePage像这样:

 class RemovePage: IVsHierarchy
    {
        public int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp)
        {
            throw new NotImplementedException();
        }

        public int GetSite(out Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP)
        {
            throw new NotImplementedException();
        }

        public int QueryClose(out int pfCanClose)
        {
            throw new NotImplementedException();
        }

        public int Close()
        {
            throw new NotImplementedException();
        }

        public int GetGuidProperty(uint itemid, int propid, out Guid pguid)
        {
            throw new NotImplementedException();
        }

        public int SetGuidProperty(uint itemid, int propid, ref Guid rguid)
        {
            throw new NotImplementedException();
        }

        public int GetProperty(uint itemid, int propid, out object pvar)
        {
            throw new NotImplementedException();
        }

        public int SetProperty(uint itemid, int propid, object var)
        {
            throw new NotImplementedException();
        }

        public int GetNestedHierarchy(uint itemid, ref Guid iidHierarchyNested, out IntPtr ppHierarchyNested, out uint pitemidNested)
        {
            throw new NotImplementedException();
        }

        public int GetCanonicalName(uint itemid, out string pbstrName)
        {
            throw new NotImplementedException();
        }

        public int ParseCanonicalName(string pszName, out uint pitemid)
        {
            throw new NotImplementedException();
        }

        public int Unused0()
        {
            throw new NotImplementedException();
        }

        public int AdviseHierarchyEvents(IVsHierarchyEvents pEventSink, out uint pdwCookie)
        {
            throw new NotImplementedException();
        }

        public int UnadviseHierarchyEvents(uint dwCookie)
        {
            throw new NotImplementedException();
        }

        public int Unused1()
        {
            throw new NotImplementedException();
        }

        public int Unused2()
        {
            throw new NotImplementedException();
        }

        public int Unused3()
        {
            throw new NotImplementedException();
        }

        public int Unused4()
        {
            throw new NotImplementedException();
        }
    }

然后您可以使用这些方法修改代码。

希望它可以帮助您。

© www.soinside.com 2019 - 2024. All rights reserved.