18

I'm not talking about a post build event for a project. Rather, I want to run an executable automatically after the entire solution is built. Is there a way to do a post build event for the solution?

Kilhoffer
  • 32,375
  • 22
  • 97
  • 124

2 Answers2

23

Visual Studio 2010 and before

You can do this in the Macro Editor by handling OnBuildDone. The event gives you a couple of handy properties you can check: scope (project/solution/batch) and action (build/rebuild/clean/deploy). To do what you want would be something like this (not tested, mind):

Public Sub AfterBuild(scope As vsBuildScope, action As vsBuildAction) _
        Handles BuildEvents.OnBuildDone
    If scope = vsBuildScope.vsBuildScopeSolution Then
        System.Diagnostics.Process.Start("some file I want to run")
    End If
End Sub

Visual Studio 2012

The solution above won't work in Visual Studio 2012 because Microsoft has removed macros in that version. However, you can still do essentially the same thing with an add-in. To see how, go here:

Alternative to Macros in Visual Studio 2012

Community
  • 1
  • 1
Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211
  • That's awesome! Exactly what i wanted. If I could up vote you more, I certainly would! – Kilhoffer Oct 07 '08 at 14:34
  • 1
    So this will need to be added to every machine that does builds or is it saved with the Solution file? – Jeroen Ritmeijer Dec 08 '10 at 16:54
  • 1
    Macros are machine-specific, so you'd need to put it on every machine. Another option is to put a post-build event on the last project in the build sequence. A post-build event (in project properties) *will* be saved in source control with the project. – Ryan Lundy Dec 08 '10 at 18:46
4

not directly.
you can make a project which has a dependency in all other projects and add a post build step to it. Effectively this will cause it to run after everything else.

shoosh
  • 76,898
  • 55
  • 205
  • 325