有人可能有示例代码吗?
其实,按照指导,你就能得到你想要的。
遵循本指南:
删除属性页
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) 之后在页面底部添加main函数实现:
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)添加main函数,如文件底部所说的:
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();
}
}
然后你可以在这些方法中修改你的代码。
希望对你有帮助。