VS2010 Build and Debug Startup Project

4 11 2011

In large solutions, I often have the need to build and/or debug only the selected startup project.

The main benefit of this is that Visual Studio keeps from building the entire solution when you select Debug – Start new instance from a project’s context menu in the Solution Explorer view. This is different from the behavior when you select Debug – Start Debugging from the main menu. In the latter case, the whole solution is always built which might cause problems when one or more of the generated output artefacts are in use by the system (e. g. running executables).

Today I wrote the following two Visual Studio macros and assigned them to the hotkey Ctrl+B (BuildStartupProject) and Ctrl+D (DebugStartupProject) and it made me happier.

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module StartupProjectCommands
Sub BuildStartupProject()
  ' Build startup project
  Dim sb As SolutionBuild = DTE.Solution.SolutionBuild
  Dim projName As String = sb.StartupProjects(0)
  sb.BuildProject(sb.ActiveConfiguration.Name, projName, False)
End Sub

Sub DebugStartupProject()
  ' Get startup project name
  Dim sb As SolutionBuild = DTE.Solution.SolutionBuild
  Dim projName As String = sb.StartupProjects(0)
  Dim index As Integer = projName.LastIndexOf(".")
  If (index > 0) Then
    projName = projName.Substring(0, index)
    ' Activate SolutionExplorer
    ' Select startup project
    ' Debug startup project
  End If
End Sub

End Module



Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Google Foto

Du kommentierst mit Deinem Google-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s

%d Bloggern gefällt das: