views:

206

answers:

1

I know you can have pre and post build events at a project level, but I want to stop and start a service at the beginning and end of a build of the solution -- i.e. when I do a 'Build Solution' the service is stopped and the last action of the build is to re-start the service.

There are no build events on the solution property page, so what should I do?

I'm guessing that I can add tasks to the msbuild file but I'm afraid I don't understand the relationship between VS and msbuild at all. Does VS execute msbuild with the SLN file?

+2  A: 

I wrote a Macro for my own project as I needed this exact functionality:

You can write a Macro that does this for you. Go to Tools -> Macros IDE

Once there, double click on the EnvironmentEvents module and add this code:

Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
    If (Scope = EnvDTE.vsBuildScope.vsBuildScopeSolution)
        //Do whatever solution independent stuff you need here.
        If(DTE.Solution.FullName = "C:\My Solutions\Solution1.sln")
           //Do whatever you need for Solution1.sln here.
        End If
    End If
End Sub

Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
    If (Scope = EnvDTE.vsBuildScope.vsBuildScopeSolution)
        //Do whatever solution independent stuff you need here.
        If(DTE.Solution.FullName = "C:\My Solutions\Solution1.sln")
           //Do whatever you need for Solution1.sln here.
        End If
    End If
End Sub
Praveen Angyan
That looks like it's solution independent. If I build *any* solution that will fire -- am I right?
nickd
I've modified the code to allow you to do solution dependent logic based on the full path of a solution. Keep in mind that 1) I am not a master of macros, just a beginner, 2) I need to use macros because I can't use MSBuild.
Praveen Angyan
I had hoped for a solution that I could tie to the .sln so that all developers could pick it up as part of their build. This doesn't seem possible, so I'm happy to use this approach.
nickd