I am writing a macro to save all open documents, launch MSBuild to build C# projects in parallel, and then run the solution using the debugger. Automating these steps in a reliable way will save my team a lot of time.
My problem is I can't get DTE.Debugger.Go(False) to work when the external build changes the output files.
Error
Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE80.DTE2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2EE1E9FA-0AFE-4348-A89F-ED9CB45C99CF}' failed due to the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)).
OK
Here is the macro definition I have:
Private Function SaveAllDocuments() As Boolean
Dim doc As Document
For Each doc In DTE.Documents
If Not doc.Saved Then
If (doc.Save(doc.FullName) <> vsSaveStatus.vsSaveSucceeded) Then
Return False
End If
End If
Next
Return True
End Function
Sub ParallelBuildAndRun()
If (SaveAllDocuments() = True) Then
Dim p As System.Diagnostics.Process
Dim fileNa开发者_如何学运维me As String
Dim args As String
fileName = "C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe"
args = "/p:Configuration=""" _
+ DTE.Solution.SolutionBuild.ActiveConfiguration.Name _
+ """ /m """ + DTE.Solution.FullName + """"
p = System.Diagnostics.Process.Start(fileName, args)
p.WaitForExit()
If (p.ExitCode = 0) Then
' Not even the evil DoEvents helps here.
'Application.DoEvents()
' This line will crash if the output files that are
' going to be debugged changed while in this macro
DTE.Debugger.Go(False)
End If
End If
End Sub
精彩评论