如何以编程方式启动Visual Studio并将其发送到特定的文件/行? [英] How can I programmatically launch visual studio and send it to a specific file / line?
问题描述
我有一种捕捉未处理异常的好方法我会显示给用户,并(可选)通过电子邮件发送给我自己.它们通常看起来像这样:
I have a nice tidy way of capturing unhandled exceptions which I display to my users and (optionally) get emailed to myself. They generally look something like this:
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
,如果可以,怎么办?
Is it possible to launch visual studio and have it open c:\projects\myapp\somelibrary.h
on the offending line and if so, how?
如果可能的话,我也想从生成的(html)电子邮件中做到这一点?
I'd also like to do this from the (html) email I generate if that's possible?
推荐答案
您可以使用例如VBScript自动化Visual Studio:
You can automate Visual Studio, using for example 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
并运行,将文件名和行号作为命令行参数传递:
Save this as say debugger.vbs
and run it, passing the filename and line no as command line args:
debugger.vbs c:\dev\my_file.cpp 42
这篇关于如何以编程方式启动Visual Studio并将其发送到特定的文件/行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!