次の方法で共有


方法 : ソリューションとプロジェクトのビルド構成を作成する

Visual Studio オートメーション モデルには、ソリューションおよびプロジェクトのビルド構成を制御できるオブジェクトが用意されています。 ソリューション ビルド構成によって、ソリューション内の特定のプロジェクトをビルドする方法が指定されます。また、有効な場合は、そのプロジェクトを配置する方法も指定されます。 プロジェクト ビルド構成は、[<プロジェクト名> プロパティ ページ] ダイアログ ボックスにその一覧が表示されます。プロジェクト ビルド構成では、使用できるプロジェクト ビルドの種類 (デバッグ バージョンやリリース バージョンなど) および使用できるプラットフォーム (.NET や Win32 など) の一覧が表示されます。 ビルドとプラットフォームの組み合わせごとに、プロジェクト構成があります。プロジェクト構成とは、定義済みのプロジェクト プロパティと設定のセットです。

ソリューション ビルド構成オブジェクトには、次のようなオブジェクトがあります。

オブジェクト名

説明

SolutionBuild2 オブジェクト

現在アクティブなソリューション構成のビルド、削除、および配置を実行します。

SolutionConfiguration2 オブジェクト

ビルドされるプロパティとその構成の一覧を表します。

SolutionConfigurations コレクション

定義されたすべての SolutionConfiguration オブジェクトを含みます。

SolutionContext オブジェクト

SolutionConfiguration オブジェクト内のプロジェクトの構成を表します。

SolutionContexts コレクション

SolutionConfiguration オブジェクト内のすべての SolutionContext オブジェクトを含みます。

BuildDependency オブジェクト

所有するプロジェクトをビルドする前に、ビルドする必要のあるプロジェクトを表します。

BuildDependencies コレクション

所有するプロジェクトをビルドする前に、ビルドする必要のあるすべてのプロジェクトを含みます。

プロジェクト ビルド構成オブジェクトには、次のようなオブジェクトがあります。

オブジェクト名

説明

ConfigurationManager オブジェクト

ビルド構成とプラットフォームを表します。

Configuration オブジェクト

指定したプラットフォームにおける構成、または一連のビルド設定を表します。

Configurations コレクション

すべての Configuration オブジェクトを含みます。

OutputGroup オブジェクト

プロジェクトによってビルドされるファイルを含みます。

OutputGroups コレクション

すべての OutputGroup オブジェクトを含みます。

これらのオブジェクトを使用すると、以下のことができます。

  • ソリューション構成の作成、アクティブ化、削除、またはソリューション構成へのプロジェクトの追加。

  • ソリューション構成内のプロジェクトのビルド、実行、または配置。

  • プロジェクトやソリューション構成内のオブジェクトに関する情報の取得。

  • プロジェクト ビルドの依存関係に関する情報の追加、削除、または取得。

注意

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

使用例

Public 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)
    SConfig(_applicationObject)
End Sub
Sub SConfig(ByVal dte As DTE2)
    Dim SB As SolutionBuild2 =  _
    CType(_applicationObject.Solution.SolutionBuild, _
    SolutionBuild2)
    Dim SolCtx As SolutionContext
    Dim Proj As Project
    Dim CM As ConfigurationManager
    Dim Cfgs As SolutionConfigurations
    Dim Cfg As SolutionConfiguration2
    Dim msg As String

    ' Get a reference to the solution configurations 
    ' solution context of the first project.
    SolCtx = SB.SolutionConfigurations.Item(1).SolutionContexts.Item(1)
   CM = _applicationObject.Solution.Projects. _
    Item(1).ConfigurationManager
    Proj = _applicationObject.Solution.Projects.Item(1)
    Cfgs = _applicationObject.Solution.SolutionBuild. _
    SolutionConfigurations
    Cfg = CType(Cfgs.Item(1), SolutionConfiguration2)

    ' List the current solution build info.
    msg = "BuildState = "
    Select Case SB.BuildState
        Case vsBuildState.vsBuildStateNotStarted
            msg = msg & "Build has not yet started." & vbCr
        Case vsBuildState.vsBuildStateInProgress
            msg = msg & "Build is in progress." & vbCr
        Case vsBuildState.vsBuildStateDone
            msg = msg & "Build has completed." & vbCr
    End Select
    msg = msg & "Configuration Name = " & SolCtx.ConfigurationName _
    & vbCr
    msg = msg & "Platform Name = " & SolCtx.PlatformName & vbCr
    msg = msg & "Project Name = " & SolCtx.ProjectName & vbCr
    MsgBox(msg)

    ' List the current solution configurations.
    msg = ("Configuration names are:" & vbCr)
    For Each Cfg In Cfgs
        msg = msg & Cfg.Name & vbCr
    Next
    MsgBox(msg)
   ' Add a new solution configuration.
   Cfgs.Add("ANewConfiguration", "Debug", False)
   MsgBox(Cfgs.Item(1).Name)
   ' Create a new project build configuration based on the Debug 
   ' configuration.
   Proj.ConfigurationManager.AddConfigurationRow("MyNewConfig", _
    "Debug", True)
   ' Build the solution configuration.
   sb.SolutionConfigurations.Item("MyConfig").Activate()
   sb.Build()
End Sub
public void OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    SConfig(_applicationObject);
}
public void SConfig(DTE2 dte)
{
    try
    {
        SolutionBuild2 SB =
 (SolutionBuild2)_applicationObject.Solution.SolutionBuild;
        SolutionContext SolCtx;
        Project Proj;
        ConfigurationManager CM;
        SolutionConfigurations Cfgs;
        SolutionConfiguration2 Cfg;
        String msg;
        // Get a reference to the solution configurations
        // solution context of the first project.
        SolCtx = SB.SolutionConfigurations.Item(1).
SolutionContexts.Item(1);
        CM = dte.Solution.Projects.Item(1).ConfigurationManager;
        Proj = _applicationObject.Solution.Projects.Item(1);
        Cfgs = _applicationObject.Solution.
SolutionBuild.SolutionConfigurations;
        Cfg = (SolutionConfiguration2)Cfgs.Item(1);
        // List the current solution build info.
        msg = "BuildState = ";
        switch (SB.BuildState)
        {
            case vsBuildState.vsBuildStateNotStarted:
                msg = (msg + "Build has not yet started." + "\n");
            break;
            case vsBuildState.vsBuildStateInProgress:
                msg = (msg + "Build is in progress." + "\n");
            break;
            case vsBuildState.vsBuildStateDone:
                msg = (msg + "Build has completed." + "\n");
            break;
        }
        msg = msg + "Configuration Name = " + 
SolCtx.ConfigurationName + "\n";
        msg = msg + "Platform Name = " + SolCtx.PlatformName + "\n";
        msg = msg + "Project Name = " + SolCtx.ProjectName + "\n";
        MessageBox.Show(msg);
        // List the current solution configurations.
        msg = "Configuration names are:" + "\n";
        foreach(SolutionConfiguration2 tempConfigs in Cfgs)
        {
            msg = msg + tempConfigs.Name + "\n";
        }
        MessageBox.Show(msg);
        // Add a new solution configuration.
        Cfgs.Add("ANewConfiguration", "Debug", false);
        MessageBox.Show
("The name of the first solution configuration item is: " 
+ Cfgs.Item(1).Name);
        // Create a new project build configuration based on the 
        // Debug configuration.
        Proj.ConfigurationManager.AddConfigurationRow
("MyNewConfig", "Debug", true);
        // Build the debug solution configuration.
        MessageBox.Show("Build the solution in the debug mode...");
        SB.SolutionConfigurations.Item("Debug").Activate();
        SB.Build(true);
    }
    catch (Exception ex)
    {
        MessageBox.Show("Exception: " + ex);
    }
}

コードのコンパイル

このコードをコンパイルするには、新しい Visual Studio アドイン プロジェクトを作成し、Connect.cs クラスまたは Connect.vb クラスのコードをこの例のコードと置き換えます。 アドインを実行する前に、Visual Studio IDE でプロジェクトを開きます。 アドインの実行方法については、「方法: アドイン マネージャーを使用してアドインを制御する」を参照してください。

参照

処理手順

方法 : コマンドを追加、処理する

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

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

概念

ソリューション、プロジェクト、および項目の概要

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

その他の技術情報

Visual Studio でのビルド

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

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

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