如何在 Microsoft Visual Studio Community 2022(64 位)版本 17.3.6 中使用 COM 自动化“开始调试”和“切换断点”?
我不确定我需要打电话做什么。 我尝试使用 oleview.exe 来查找 api,但不知道如何使用它。
此代码中省略了错误处理:
import win32com.client as win32
gotoFile = "c:\\SomeFile.cpp"
gotoLine = 123
gotoChar = 12
breakpointFile = "c:\\SomeFile.cpp"
breakpointLine = 23
app = win32.GetActiveObject('VisualStudio.DTE')
app.MainWindow.Activate
app.MainWindow.Visible = True
app.UserControl = True
app.ItemOperations.OpenFile(gotoFile)
app.ActiveDocument.Selection.MoveToLineAndOffset(gotoLine, gotoChar)
app.{Toggle breakpoint in breakpointFile on breakpointLine (F9)} # How?
app.{Start Debugging (F5)} # How?
由于您需要执行的所有操作都在 VS 中定义为命名命令,因此您可以使用 DTE.ExecuteCommand 方法:
app.ExecuteCommand("Debug.ToggleBreakpoint")
app.ExecuteCommand("Debug.Start")
您可以在
Tools > Options > Environment > Keyboard
中轻松找到所有VS命令。只需开始在“显示包含的命令”字段中键入所需的文本,例如“开始”。您将获得相关命令。