Share via


Creating Solution and Project Build Configurations

The Visual Studio .NET automation model offers objects that allow you to control solution and project build configurations. A solution build configuration specifies how certain projects in a solution are to be built and, if enabled, deployed. Project build configurations are listed in the Project Property Pages dialog box and list all of the available types of project builds, such as Debug or Release, and the available platforms, such as .Net or Win32. For each combination of kind of build and platform, there is a project configuration — a set of defined project properties and settings.

The solution build configuration objects are:

Object Name Description
SolutionBuild object Used to build, clean, and deploy the currently active Solution Configuration.
SolutionConfiguration object Represents a list of projects and their configurations that are to be built.
SolutionConfigurations collection Contains all of the defined SolutionConfiguration objects.
SolutionContext object Represents a projects configuration in a SolutionConfiguration object.
SolutionContexts collection Contains all of the SolutionContext objects in a SolutionConfiguration object.
BuildDependency object Represents a project that must be built before the owning project can be built.
BuildDependencies collection Contains all of the projects that must be built before the owning project can be built.

The project build configuration objects are:

Object Name Description
ConfigurationManager object Represents build configuration and platforms.
Configuration object Represents a configuration, or set of build settings, within a specified platform.
Configurations collection Contains all of the Configuration objects.
OutputGroup object Contains the files that are built by the project.
OutputGroups collection Contains all of the OutputGroup objects.

Using these objects you can:

  • Create, add projects to, activate, and delete solution configurations.
  • Build, run, or deploy any project in a solution configuration.
  • Obtain information about objects within a project or solution configuration.
  • Add, remove, or get information about project build dependencies.

Solution and Project Configurations Examples

Sub SConfig()
   Dim SB As SolutionBuild = DTE.Solution.SolutionBuild
   Dim SolCtx As SolutionContext
   Dim Proj As Project
   Dim CM As ConfigurationManager
   Dim Cfgs As SolutionConfigurations
   Dim Cfg As SolutionConfiguration
   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 = DTE.Solution.Projects.Item(1).ConfigurationManager
   Proj = DTE.Solution.Projects.Item(1)
   Cfgs = DTE.Solution.SolutionBuild.SolutionConfigurations
   Cfg = Cfgs.Item(1)

   ' 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
   msg = msg & "Full Name = " & DTE.Solution.Projects.Item("WindowsApplication8.vbproj").FullName & vbCr
   MsgBox(msg)

   ' List the current solution configurations.
   msg = ""
   For Each Cfg In Cfgs
      msg = msg & Cfg.ConfigurationName & vbCr
      msg = msg & Cfg.Owner & vbCr
      msg = msg & Cfg.PlatformName & vbCr
      msg = msg & Cfg.Type & vbCr
    Next
End Sub

Sub CreateSolnConfig()
   ' 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)
End Sub

Sub SolutionBuildExample()
   ' Build the solution configuration
   Dim sb As SolutionBuild = DTE.Solution.SolutionBuild
   sb.SolutionConfigurations.Item("MyConfig").Activate()
   sb.Build()
End Sub

Sub SolutionConfigurationExample()
   ' Ensure that all Debug project configurations are built for the
   ' Debug solution configuration.
   Dim config As SolutionConfiguration = DTE.Solution.SolutionBuild.SolutionConfigurations.Item("Debug")
   Dim context As SolutionContexts
   For Each context In config.SolutionContexts
      Context.ConfigurationName = "Debug"
   Next
End Sub

Sub BuildDependenciesExample(ByVal p1 As Project, ByVal p2 As Project)
   ' This example requires the presence of two projects in the IDE.
   ' Make Project1 dependent upon Project2.
   Dim sb As SolutionBuild = DTE.Solution.SolutionBuild
   sb.BuildDependencies.Item(p1.UniqueName).AddProject(p2.UniqueName)
End Sub

Sub ConfigurationExample()
   ' Sets the project configuration option Define Trace value to False.
   ' This examples requires that you have a Visual Basic .NET project 
   ' loaded.
   ' The Define Trace option is on the Build node of Configuration 
   ' properties on the Project Properties page.
   Dim Proj As Project = DTE.Solution.Projects.Item(1)

   MsgBox("Property name: " & Proj.ConfigurationManager.Item("Debug", ".NET").Properties.Item(3).Name)
   MsgBox("Current value: " & Proj.ConfigurationManager.Item("Debug", ".NET").Properties.Item(3).Value)
   Proj.ConfigurationManager.Item("Debug", ".NET").Properties.Item("DefineTrace").Value = False
   MsgBox("New value: " & Proj.ConfigurationManager.Item("Debug", ".NET").Properties.Item(3).Value)
End Sub

See Also

Default and Custom Builds | Introduction to Solutions, Projects, and Items | Adding and Handling Commands | Creating and Controlling Environment Windows | Creating Add-Ins and Wizards | Creating an Add-In | Creating a Wizard | Automation and Extensibility Reference | Automation Object Model Chart