次の方法で共有


方法 : ソリューション エクスプローラーを制御する

Visual Studio アドインは、Visual Studio 2013 では使用されなくなりました。 アドインを VSPackage 拡張機能にアップグレードしてください。 アップグレードの詳細については、「FAQ: アドインを VSPackage 拡張に変換する」を参照してください。

ソリューション エクスプローラーは、Visual Studio 統合開発環境 (IDE: Integrated Development Environment) 内のツール ウィンドウで、ソリューションの内容が表示されます。ソリューションの内容には、そのソリューションのプロジェクトや各プロジェクトの項目などがあります。 Visual Studio の他のツール ウィンドウと同様に、サイズ、位置、ドッキングされた状態とフローティング状態のどちらであるかなどの、物理的なパラメーターを制御できます。 このツール ウィンドウを操作する方法については、Visual Studio の他のツール ウィンドウと同様に、「方法 : ウィンドウの特性を変更する」を参照してください。

ソリューション エクスプローラー自体は独自のオートメーション オブジェクトを持っていませんが、UIHierarchy を使用することにより、ソリューションの階層の内容をある程度制御できます。 ソリューション内のプロジェクトおよびプロジェクト項目を制御するには、プロジェクト オートメーション モデルを使用します。 詳細については、「プロジェクトとソリューションの制御」を参照してください。

注意

実際に画面に表示されるダイアログ ボックスとメニュー コマンドは、アクティブな設定またはエディションによっては、ヘルプの説明と異なる場合があります。ここに記載されている手順は、全般的な開発設定が適用されているものとして記述されています。設定を変更するには、[ツール] メニューの [設定のインポートとエクスポート] をクリックします。詳細については、「Visual Studio での開発設定のカスタマイズ」を参照してください。

UIHierarchy を使用してソリューション エクスプローラーを制御するには

  1. ソリューション エクスプローラーが表示されていない場合は、[表示] メニューの [ソリューション エクスプローラー] をクリックします。

  2. アドイン プロジェクトなどの多数の要素を持つプロジェクトを開きます。

  3. ソリューション エクスプローラーで、少なくとも 2 つの下位ノードを持つノードをクリックします。

  4. 次のコードを実行します。

使用例

UIHierarchy を使用してソリューション エクスプローラーを操作する方法の例を次に示します。

Imports System.Text
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE100Public Sub OnConnection(ByVal application As Object, ByVal _
  connectMode As ext_ConnectMode, ByVal addInInst As Object, _
  ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    ' Pass the applicationObject member variable to the code example.
    slnExplUIHierarchyExample(_applicationObject)
End Sub

Sub slnExplUIHierarchyExample(ByVal dte As DTE2)
    Dim UIH As UIHierarchy = dte.ToolWindows.SolutionExplorer
    ' Requires a reference to System.Text.
    ' Set a reference to the first level nodes in Solution Explorer. 
    ' Automation collections are one-based.
    Dim UIHItem As UIHierarchyItem = UIH.UIHierarchyItems.Item(1)
    Dim file As UIHierarchyItem
    Dim sb As New StringBuilder

    ' Iterate through first level nodes.
    For Each file In UIHItem.UIHierarchyItems
        sb.AppendLine(file.Name)
        ' Iterate through second level nodes (if they exist).
        Dim subitem As UIHierarchyItem
        For Each subitem In file.UIHierarchyItems
            sb.AppendLine("   " & subitem.Name)
            ' Iterate through third level nodes (if they exist).
            Dim subSubItem As UIHierarchyItem
            For Each subSubItem In subitem.UIHierarchyItems
                sb.AppendLine("        " & subSubItem.Name)
            Next
        Next
    Next
    MsgBox(sb.ToString)
 End Sub
using System.Text;
using EnvDTE;
using EnvDTE80;
using EnvDTE90;
using EnvDTE100;public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    slnExplUIHierarchyExample(_applicationObject);
}

public void slnExplUIHierarchyExample(DTE2 dte)
{
    UIHierarchy UIH = dte.ToolWindows.SolutionExplorer;
    // Requires a reference to System.Text.
    // Set a reference to the first level nodes in Solution Explorer. 
    // Automation collections are one-based.
    UIHierarchyItem UIHItem = UIH.UIHierarchyItems.Item(1);
    StringBuilder sb = new StringBuilder();

    // Iterate through first level nodes.
    foreach ( UIHierarchyItem fid in UIHItem.UIHierarchyItems )
    {
        sb.AppendLine(fid.Name);
        // Iterate through second level nodes (if they exist).
        foreach ( UIHierarchyItem subitem in fid.UIHierarchyItems )
        {
            sb.AppendLine("   "+subitem.Name);
            // Iterate through third level nodes (if they exist).
            foreach ( UIHierarchyItem subSubItem in 
              subitem.UIHierarchyItems )
            {
                sb.AppendLine("        "+subSubItem.Name);
            }
        }
    }
    System.Windows.Forms.MessageBox.Show(sb.ToString());
}

参照

処理手順

方法 : アドインを作成する

チュートリアル : ウィザードの作成

概念

VSProject2 オブジェクトの概要

オートメーション オブジェクト モデルの階層図

その他の技術情報

環境ウィンドウの作成と制御

アドインおよびウィザードの作成

オートメーションと機能拡張のリファレンス