我知道您可以在项目级别拥有前期和后期构建事件,但我想在解决方案构建的开始和结束时停止并启动服务 - 即当我执行“构建解决方案”时服务已停止,构建的最后一个操作是重新启动服务。
解决方案属性页面上没有构建事件,所以我该怎么办?
我猜我可以在msbuild文件中添加任务但是我恐怕根本不理解VS和msbuild之间的关系。 VS是否使用SLN文件执行msbuild?
答案 0 :(得分:3)
我为自己的项目编写了一个宏,因为我需要这个确切的功能:
您可以编写一个为您执行此操作的宏。转到工具 - >宏IDE
在那里,双击EnvironmentEvents模块并添加以下代码:
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