gpt4 book ai didi

.net - 如何以编程方式启动 visual studio 并将其发送到特定文件/行?

转载 作者:行者123 更新时间:2023-11-30 01:31:23 25 4
gpt4 key购买 nike

我有a nice tidy way of capturing unhandled exceptions我向我的用户显示并(可选)通过电子邮件发送给我自己。它们通常看起来像这样:

Uncaught exception encountered in MyApp (Version 1.1.0)!

Exception:
Object reference not set to an instance of an object.
Exception type:
System.NullReferenceException
Source:
MyApp
Stack trace:
at SomeLibrary.DoMoreStuff() in c:\projects\myapp\somelibrary.h:line 509
at SomeAlgothim.DoStuff() in c:\projects\myapp\somealgorithm.h:line 519
at MyApp.MainForm.ItemCheckedEventHandler(Object sender, ItemCheckedEventArgs e) in c:\projects\myapp\mainform.cpp:line 106
at System.Windows.Forms.ListView.OnItemChecked(ItemCheckedEventArgs e)
at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

是否可以启动 visual studio 并在有问题的行上打开 c:\projects\myapp\somelibrary.h,如果可以,怎么做?

如果可能的话,我还想从我生成的 (html) 电子邮件中执行此操作?

最佳答案

您可以自动化 Visual Studio,例如使用 VBScript:

filename = Wscript.Arguments(0)
lineNo = Wscript.Arguments(1)

' Creates an instance of the Visual Studio IDE.
Set dte = CreateObject("VisualStudio.DTE")

' Make it visible and keep it open after we finish this script.
dte.MainWindow.Visible = True
dte.UserControl = True

' Open file and move to specified line.
dte.ItemOperations.OpenFile(filename)
dte.ActiveDocument.Selection.GotoLine (lineNo)

将其保存为 debugger.vbs 并运行它,将文件名和行号作为命令行参数传递:

debugger.vbs c:\dev\my_file.cpp 42

关于.net - 如何以编程方式启动 visual studio 并将其发送到特定文件/行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3116286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com