Compartilhar via


SolutionBuild2.BuildProject Method

Builds the specified project and its dependencies in the context of the specified solution configuration.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

'Declaration
Sub BuildProject ( _
    SolutionConfiguration As String, _
    ProjectUniqueName As String, _
    WaitForBuildToFinish As Boolean _
)
void BuildProject(
    string SolutionConfiguration,
    string ProjectUniqueName,
    bool WaitForBuildToFinish
)
void BuildProject(
    String^ SolutionConfiguration, 
    String^ ProjectUniqueName, 
    bool WaitForBuildToFinish
)
abstract BuildProject : 
        SolutionConfiguration:string * 
        ProjectUniqueName:string * 
        WaitForBuildToFinish:bool -> unit
function BuildProject(
    SolutionConfiguration : String, 
    ProjectUniqueName : String, 
    WaitForBuildToFinish : boolean
)

Parameters

  • SolutionConfiguration
    Type: String

    Required. The name of the new solution configuration that provides the context in which to build the project.

  • ProjectUniqueName
    Type: String

    Required. The project to build.

  • WaitForBuildToFinish
    Type: Boolean

    Optional. Determines whether to wait for the build to complete. If true, then it waits, otherwise, it does not wait.

Remarks

BuildProject returns immediately. To determine when a solution build operation is complete, you must check the OnBuildDone event.

BuildProject does not affect the user interface (UI) in terms of changing the active solution configuration or selected project. If you want to build the project relative to the active solution configuration, use DTE.SolutionBuild.ActiveConfiguration.Name.

BuildProject does affect the UI based on the DTE.SuppressUI flag in that the Status Bar flickers and the Output Window and Task List are always updated.

BuildProject builds the specified project and all of its dependencies that are checked to be built in the specified solution configuration.

Examples

This example builds a project in debug mode. Open a project in the Visual Studio integrated development environment (IDE) before running this add-in.

For more information about how to run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.

Imports EnvDTE
Imports EnvDTE80
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)
    SolutionBuildProjectExample(_applicationObject)
End Sub
Sub SolutionBuildProjectExample(ByVal dte As DTE2)
    ' Open a solution in Visual Studio before running this example.
    Try
        Dim soln As Solution2 = CType(_applicationObject.Solution, _
        Solution2)
        Dim sb As SolutionBuild2
        Dim bld As BuildDependencies
        Dim p1 As Project = soln.Projects.Item(1)
        sb = CType(soln.SolutionBuild, SolutionBuild2)
        bld = sb.BuildDependencies
        MsgBox("The project " & bld.Item(1).Project.Name & " has "  _
        & bld.Count.ToString() & " build dependencies.")
        MsgBox("Building the project in debug mode...")
        sb.BuildProject("Debug", p1.FullName, True)
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application,
 ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    SolutionBuildProjectExample(_applicationObject);
}
public void SolutionBuildProjectExample(DTE2 dte)
{
    try
    {
        Solution2 soln = (Solution2)_applicationObject.Solution;
        SolutionBuild2 sb;
        BuildDependencies bld;
        Project p1 = soln.Projects.Item(1);
        // Open a solution in Visual Studio before 
        // running this example.
        sb = (SolutionBuild2)soln.SolutionBuild;
        bld = sb.BuildDependencies;
        MessageBox.Show("The project " + bld.Item(1).Project.Name 
+ " has " + bld.Count.ToString() + " build dependencies.");
        MessageBox.Show("Building the project in debug mode...");
        sb.BuildProject("Debug", p1.FullName,true);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework Security

See Also

Reference

SolutionBuild2 Interface

EnvDTE80 Namespace