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

标签 .net c++ visual-studio-2008 exception error-reporting

我有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/

相关文章:

visual-studio - Visual Studio 中的 "Error generating Win32 resource",Windows 7 x64

visual-studio - 如何将 INF 驱动程序安装包含到 VS 安装程序项目中

c# - 在运行时查找对对象的引用

两个协变接口(interface)的 C# 协变问题

c++ - 计算字符串中元音的个数

c++ - wxWidgets 从套接字读取

c++ - 在arm-linux-gnueabihf-g++交叉编译期间出错。无法识别共享库文件

visual-studio-2008 - Visual Studio 项目模板

c# - 为什么我不能通过索引访问 KeyedCollection 项目?

c# - HttpWebResponse 超时