问题
I have the following Visual Studio Macro:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports MyMacros.EnvironmentEvents
Imports System.Diagnostics
Public Module Module1
Private WithEvents buildEvents As EnvDTE.BuildEvents = EnvironmentEvents.BuildEvents
Public Sub BuildEvents_OnBuildBegin() Handles buildEvents.OnBuildBegin
Dim projectItem As ProjectItem = DTE.Solution.FindProjectItem("T4MVCVB.tt")
projectItem.Save()
End Sub
End Module
I can run it from the Macro explorer, and it works great, and after i have double clicked it from the macro explorer and it has run, the eventhandler is invoked on build.
But if I haven't manually run the macro, the eventhandler is never invoked / event is never fired.
What am i missing here?
回答1:
I put the section in directly in the EnvironmentEvents Module outside the autogenerated region, and now it fires every time.
来源:https://stackoverflow.com/questions/2345467/onbuildbegin-does-not-fire-in-visual-studio-macro-until-i-run-it-from-macro-expl