Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

msbuild - Solution level build events in VS 2008

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 SolutionsSolution1.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 SolutionsSolution1.sln")
           //Do whatever you need for Solution1.sln here.
        End If
    End If
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...