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)
  DTE.ExecuteCommand("View.Output")
  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
    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
    ' Select startup project
    DTE.ActiveWindow.Object.GetItem(projName).Select(vsUISelectionType.vsUISelectionTypeSelect)
    ' Debug startup project
    DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance")
  End If
End Sub

End Module

Aktionen

Information

Schreibe einen Kommentar

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

WordPress.com-Logo

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

Twitter-Bild

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

Facebook-Foto

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

Google+ Foto

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

Verbinde mit %s




%d Bloggern gefällt das: