Gewusst wie: Erstellen der Buildkonfigurationen von Projektmappen und Projekten

Add-Ins für Visual Studio sind in Visual Studio 2013 veraltet. Sie müssen für Ihre Add-Ins ein Upgrade auf VSPackage-Erweiterungen durchführen. Weitere Informationen über das Durchführen eines Upgrades finden Sie unter FAQ: Konvertieren von Add-Ins in VSPackage-Erweiterungen.

Das Automatisierungsmodell von Visual Studio stellt Objekte zur Steuerung der Buildkonfigurationen von Projektmappen und Projekten zur Verfügung. Mit einer Projektmappen-Buildkonfiguration wird festgelegt, wie bestimmte Projekte in einer Projektmappe erstellt und im Falle einer Aktivierung bereitgestellt werden. Projektbuildkonfigurationen werden im Dialogfeld <Projektname>-Eigenschaftenseiten aufgelistet. Diese listen alle verfügbaren Typen von Projektbuilds auf, z. B. Debug oder Release. Ebenso werden die verfügbaren Plattformen aufgelistet, z. B. .NET oder Win32. Für jede Kombination aus Buildtyp und Plattform gibt es eine Projektkonfiguration, d. h. einen Satz mit definierten Projekteigenschaften und Einstellungen.

Die Projektmappen-Buildkonfiguration verfügt über folgende Objekte:

Objektname

Beschreibung

SolutionBuild2-Objekt

Damit wird die aktuell aktive Projektmappenkonfiguration erstellt, bereinigt und bereitgestellt.

SolutionConfiguration2-Objekt

Stellt eine Liste der zu erstellenden Projekte und ihrer Konfigurationen dar.

SolutionConfigurations-Auflistung

Enthält alle definierten SolutionConfiguration-Objekte.

SolutionContext-Objekt

Stellt die Konfiguration eines Projekts in einem SolutionConfiguration-Objekt dar.

SolutionContexts-Auflistung

Enthält alle SolutionContext-Objekte in einem SolutionConfiguration-Objekt.

BuildDependency-Objekt

Stellt ein Projekt dar, das erstellt werden muss, bevor das gewünschte Projekt erstellt werden kann.

BuildDependencies-Auflistung

Enthält alle Projekte, die erstellt werden müssen, bevor das gewünschte Projekt erstellt werden kann.

Die Projekt-Buildkonfiguration verfügt über folgende Objekte:

Objektname

Beschreibung

ConfigurationManager-Objekt

Stellt die Buildkonfiguration und Plattformen dar.

Configuration-Objekt

Stellt eine Konfiguration oder ein Satz von Buildeinstellungen innerhalb einer speziellen Plattform dar.

Configurations-Auflistung

Enthält alle Configuration-Objekte.

OutputGroup-Objekt

Enthält die durch das Projekt erstellten Dateien.

OutputGroups-Auflistung

Enthält alle OutputGroup-Objekte.

Mithilfe dieser Objekte können Sie folgende Aufgaben durchführen:

  • Projektmappenkonfigurationen erstellen, aktivieren und löschen sowie Projekte in Projektmappenkonfigurationen einfügen.

  • Projekte in einer Projektmappenkonfiguration erstellen, ausführen und bereitstellen.

  • Informationen über Objekte eines Projekts oder einer Projektmappenkonfiguration erhalten.

  • Informationen über Projekterstellungsabhängigkeiten hinzufügen, entfernen oder erhalten.

Hinweis

Je nach den aktiven Einstellungen oder der Version unterscheiden sich die Dialogfelder und Menübefehle auf Ihrem Bildschirm möglicherweise von den in der Hilfe beschriebenen.Bei der Entwicklung dieser Verfahren war die Option Allgemeine Entwicklungseinstellungen aktiviert.Wählen Sie im Menü Extras die Option Einstellungen importieren und exportieren aus, um die Einstellungen zu ändern.Weitere Informationen finden Sie unter Anpassen der Entwicklungseinstellungen in Visual Studio.

Beispiel

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);
    }
}

Kompilieren des Codes

Um den Code zu kompilieren, erstellen Sie ein neues Visual Studio-Add-In-Projekt und ersetzen den Code der Connect.cs-Klasse oder Connect.vb-Klasse durch den Code im Beispiel. Öffnen Sie vor dem Ausführen des Add-Ins ein Projekt in der IDE von Visual Studio. Informationen zum Ausführen eines Add-Ins finden Sie unter Gewusst wie: Steuern von Add-Ins mit dem Add-In-Manager.

Siehe auch

Aufgaben

Gewusst wie: Hinzufügen und Ändern von Befehlen

Gewusst wie: Erstellen von Add-Ins

Exemplarische Vorgehensweise: Erstellen eines Assistenten

Konzepte

Projektmappen und Projekte

Diagramm "Automationsobjektmodell"

Weitere Ressourcen

Anwendungen in Visual Studio erstellen

Erstellen und Steuern von Umgebungsfenstern

Erstellen von Add-Ins und Assistenten

Referenz zur Automatisierung und Erweiterbarkeit