2012-08-07 75 views
1

我期待創建一個Visual Studio AddIn,它可以幫助我啓動自己的調試過程。我想保持原來基於F5的調試完好無損,因此我不想攔截該調用並需要單獨的AddIn。Visual Studio AddIn

任何建議

回答

5

最簡單的方法是捕捉系統事件/使用插件宏。重寫這些事件與做什麼很容易。使用標準的Visual Studio命令(如F5)時,所有事件都會自動啓動。這包括所有標準的Visual Studio快捷鍵,菜單和工具欄按鈕。

創建一個新的vs插件項目,它會自動添加代碼以附加OnBeforeCommandEvent。在VB中,事件處理程序將看起來像下面的代碼。

Friend Sub OnBeforeCommandEvent(sGuid As String, ID As Integer, CustomIn As Object, CustomOut As Object, ByRef CancelDefault As Boolean) 

事件通過你sGuid和ID。可以按如下方式解決這兩個項目一個宏字符串名稱(sCommandName): -

Dim objCommand As EnvDTE.Command 

Try 
     objCommand = _applicationObject.Commands.Item(sGuid, ID) 
Catch ex As Exception 
     'unknown guids can be ignored 
     Exit Sub 
End Try 

If objCommand Is Nothing Then Exit Sub 
     Dim sCommandName As String 
     sCommandName = objCommand.Name 

注:該插件啓動時_applicationObject傳遞到您的代碼。一個新的插件項目將自動包含OnConnection事件的以下代碼,第一個參數是上面顯示的_applicationObject

OnConnection(ByVal application As Object 

一旦你有了sCommandName變量,它將包含一個Visual Studio宏如Debug.Start的名稱。

要覆蓋Debug.Start函數,那麼您將添加一些自己的代碼,並記得在退出處理程序之前將CancelDefault設置爲True

當您將CancelDefault設置爲true時,Visual Studio將不會運行標準宏,這意味着您可以在按F5時運行您自己的調試器。

這些是在構建過程中使用的Visual Studio宏名稱。你可以覆蓋儘可能多或儘可能少的。我已將它們分組到相關的功能中,但您可以以任意組合處理它們。

Select Case sCommandName 

     Case "Debug.Start", _ 
        "Debug.StartWithoutDebugging" 
        System.Windows.Forms.MessageBox.Show("You clicked F5, we are overriding the debug process") 
        CancelDefault=true 
        Exit Sub 


     Case "ClassViewContextMenus.ClassViewProject.Rebuild", _ 
        "ClassViewContextMenus.ClassViewProject.Build", _ 
        "Build.RebuildOnlyProject", _ 
        "Build.RebuildSelection", _ 
        "Build.BuildOnlyProject", _ 
        "Build.BuildSelection" 

     Case "Build.RebuildSolution", _ 
        "Build.BuildSolution" 

     Case "ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance", _ 
        "ClassViewContextMenus.ClassViewProject.Debug.StepIntonewinstance" 

     Case "Build.CleanSelection", _ 
        "Build.CleanSolution", _ 
        "ClassViewContextMenus.ClassViewProject.Clean" 

     Case "Build.SolutionConfigurations" 
相關問題