プロパティ ページの追加と削除

プロジェクト デザイナーは、Visual Studio のプロジェクトのプロパティ、設定、リソースを管理するための一元的な場所を提供します。 Visual Studio 統合開発環境 (IDE) で 1 つのウィンドウとして表示され、左側のタブからアクセスできる、多数のペインを右側に含みます。 プロジェクト デザイナーのペイン (多くの場合、プロパティ ページと呼ばれます) は、プロジェクト タイプと言語によって異なります。 プロジェクト デザイナーには、[プロジェクト] メニューの [プロパティ] からアクセスすることができます。

プロジェクトのサブタイプでは、プロジェクト デザイナーに追加のプロパティページを頻繁に表示する必要があります。 同様に、一部のプロジェクトのサブタイプでは、組み込みのプロパティ ページを削除する必要がある場合があります。 そのためには、プロジェクトのサブタイプにより IVsHierarchy インターフェイスを実装し、GetProperty メソッドをオーバーライドする必要があります。 このメソッドをオーバーライドし、__VSHPROPID2 列挙体の値の 1 つを含む propId パラメーターを使用することで、プロジェクトのプロパティをフィルター処理、追加、または削除できます。 たとえば、構成に依存するプロパティ ページにページを追加することが必要になる場合があります。 これを行うには、構成に依存するプロパティ ページをフィルター処理し、既存のリストに新しいページを追加する必要があります。

プロジェクト デザイナーでのプロパティ ページの追加と削除

プロパティ ページを削除する方法

  1. GetProperty(uint itemId, int propId, out object property) メソッドをオーバーライドして、プロパティ ページをフィルター処理し、clsids リストを取得します。

    protected override 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(base.GetProperty(itemId, propId, out property));
                    string propertyPagesList = ((string)property).ToUpper(CultureInfo.InvariantCulture);
                    //Remove the property page here
                    . . . .
                }
             . . . .
         }
            . . . .
        return base.GetProperty(itemId, propId, out property);
    }
    
  2. 取得した clsids リストから [ビルド イベント] ページを削除します。

    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;
    

プロパティ ページを追加する

  1. 追加するプロパティ ページを作成します。

    class DeployPropertyPage : Form, Microsoft.VisualStudio.OLE.Interop.IPropertyPage
    {
        . . . .
        //Summary: Return a structure describing your property page.
        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;
        }
    }
    
  2. 新しいプロパティ ページを登録します。

    [MSVSIP.ProvideObject(typeof(DeployPropertyPage), RegisterUsing = RegistrationMethod.CodeBase)]
    
  3. GetProperty(uint itemId, int propId, out object property) メソッドをオーバーライドして、プロパティ ページのフィルター処理、clsids リストの取得、新しいプロパティ ページの追加を行います。

    protected override 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(base.GetProperty(itemId, propId, out property));
                    //Add the Deployment property page.
                    property += ';' + typeof(DeployPropertyPage).GUID.ToString("B");
                }
         }
            . . . .
        return base.GetProperty(itemId, propId, out property);
    }