EnvironmentEvents
您可以通过Visual Studio 的宏资源管理器中的宏更改行为:
Private Enum IDEMode
Design = 1
Break = 2
Run = 3
End Enum
Private _IDEMode As IDEMode = IDEMode.Design
Public Sub DTEDebuggerEvents_OnDebugRun() Handles _
DebuggerEvents.OnEnterRunMode
If _IDEMode = IDEMode.Design Then
DTE.ExecuteCommand("Build.RebuildSolution")
End If
_IDEMode = IDEMode.Run
End Sub
Public Sub DTEDebuggerEvents_OnDebugDesign() Handles _
DebuggerEvents.OnEnterDesignMode
_IDEMode = IDEMode.Design
End Sub
Public Sub DTEDebuggerEvents_OnDebugBreak() Handles _
DebuggerEvents.OnEnterBreakMode
_IDEMode = IDEMode.Break
End Sub
这是一个 VisualStudio 更改,因此一旦设置,它将适用于所有解决方案
更新
上述解决方案有效,但是它有一些关于内容文件的缺陷,即使调试器正在运行,IDE 也会更改为设计模式。在某些情况下,它会在调试器运行时尝试构建。正确的解决方案是这样的:
Private _curDebugState As EnvDTE80.dbgProcessState
Public Sub debuggerStateChangedHandler
(ByVal NewProcess As EnvDTE.Process,
ByVal processState As EnvDTE80.dbgProcessState)
Handles DebuggerProcessEvents.OnProcessStateChanged
If _curDebugState = dbgProcessState.dbgProcessStateStop And processState = dbgProcessState.dbgProcessStateRun Then
DTE.ExecuteCommand("Build.RebuildSolution")
End If
_curDebugState = processState
End Sub