12

I've tried to find a keyboard shortcut to build only the startup project In VS2008.

I only found a configurable shortcut to build the project which is currently viewed, which isn't as good.

Any ideas?

Thanks.

Danra
  • 9,546
  • 5
  • 59
  • 117
  • You're right, Tools/Options/Environment/Keyboard doesn't have a `Build.StartupProject`. `:(` – sbi Nov 11 '09 at 09:43
  • A serious question, why would you only want to build the startup project? – Lazarus Nov 11 '09 at 09:48
  • 1
    Since many times the startup project is the one I'm interested in building, even if I am currently editing a different project (on which the startup project depends). – Danra Nov 11 '09 at 10:17

4 Answers4

13

That macro ought to do it:

Sub Build_Startup()
    DTE.ToolWindows.OutputWindow.Parent.Activate()
    Dim sb As SolutionBuild2 = DTE.Solution.SolutionBuild
    For Each item In sb.StartupProjects
        sb.BuildProject(sb.ActiveConfiguration.Name, item, True)
    Next
End Sub

Just put that in your macros - using the Macros IDE Alt + F11, and add a keyboard mapping to it (Tools/Customize/Commands/Keyboard, find your new command in the Macros. namespace), and you're all set.

CodeAngry
  • 12,760
  • 3
  • 50
  • 57
Bahbar
  • 17,760
  • 43
  • 62
  • Great, it works!! But... It doesn't display anything on the output console... Any way to change that? – Danra Nov 17 '09 at 13:20
  • It displays the standard build output in the build output pane for me. What kind of output are you looking for ? You can add your own output in the macro with the help of GetWindowOutputPane and OutputItem functions that are available in the macros samples (Samples/Utilities). – Bahbar Nov 17 '09 at 15:48
  • My mistake, output is indeed displayed properly. Thanks! – Danra Nov 18 '09 at 13:59
  • On VS2010 it isn't showing. The build starts, but I can't bring up the output window which normally show up if I start a build with F7. Any suggestions? – progician Sep 27 '11 at 09:32
  • Note that according to http://social.msdn.microsoft.com/Forums/vstudio/en-US/3ea91a70-5d1e-42b4-afa0-6218eb098bd9/macro-building-a-specific-project-using-a-specific-configuration-and-platform this doesn't build according to the selected platform - instead it always builds for Win32. I can't confirm this as I haven't tried it, but thought it was worth mentioning. – Michael Bray Feb 03 '14 at 06:37
  • Unfortunately, macros are gone from VS 2012 up: http://stackoverflow.com/questions/12062515/can-i-record-play-macros-in-visual-studio-2012-2013-2015 There are some plugins that try to make up for that, but still... – Tomasz Gandor May 11 '16 at 08:37
1

You could create a custom solution configuration that only builds the project you want (named for example "StartupOnly"). By default Visual Studio shows a combo in the toolbar that allows to quickly switch between different configurations, so all you would need is to select that configuration and use the regular build command.

Konamiman
  • 49,681
  • 17
  • 108
  • 138
  • I'm looking for a generic keyboard shortcut that doesn't require me to define a configuration for every project I want to build. – Danra Nov 15 '09 at 20:30
1

You can use "Build Only Startup Project" extension on VS 2019 and VS 2022.

Also to assigne keyboard shorcut, you can check "Build.BuildOnlyStartupProject" shortcut.

bafsar
  • 1,080
  • 2
  • 16
  • 16
0

Sorry, I don't have enough points to reply directly to progician above, but in VS2010, if you add the following as the first line of Bahbar's macro, the output window will display during the build

DTE.ToolWindows.OutputWindow.Parent.Activate()

Update: additionally, you need to use the following for the configuration name:

Dim configName = String.Format("{0}|{1}", sb.ActiveConfiguration.Name, sb.ActiveConfiguration.PlatformName)
Greg
  • 63
  • 3