有時候當程式碼一大,在編譯時就要等很久 這時候如果裡面有錯誤的話更是令人抓狂… Visual Studio又沒有手動停止編譯的功能,這時候該怎麼辦?

其實我們可以插入一個macro來實現這個功能 做法如下:

進到visual studioToolsMacrosMacro IDE,然後插入下面的程式碼 Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles OutputWindowEvents.PaneUpdated If Not (pPane.Name = “Build”) Then Exit Sub pPane.TextDocument.Selection.SelectAll() Dim Context As String = pPane.TextDocument.Selection.Text pPane.TextDocument.Selection.EndOfDocument() Dim found As Integer = Context.IndexOf(”: error ”) If found > 0 Then ‘有找到錯誤就停止 DTE.ExecuteCommand(“Build.Cancel”) End If End Sub 如下圖:

這樣在發生第一個錯誤時就會停止編譯了

參考:http://zh-tw.w3support.net/index.php?db=so&id=134796