VS 2008 中的解决方案级构建事件 [英] Solution level build events in VS 2008

查看:22
本文介绍了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?

我猜我可以在 msbuild 文件中添加任务,但我担心我根本不了解 VS 和 msbuild 之间的关系.VS 是否使用 SLN 文件执行 msbuild?

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?

推荐答案

我为自己的项目编写了一个宏,因为我需要这个确切的功能:

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

您可以编写一个宏来为您执行此操作.转到工具 -> 宏 IDE

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

在那里,双击 EnvironmentEvents 模块并添加以下代码:

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

这篇关于VS 2008 中的解决方案级构建事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆