![](/img/trans.png)
[英]How can I get the current Active Solution Platform name for use in a Visual Studio add-in? (C#)
[英]How to get the current line number at break/exception in Visual Studio add-in?
我正在搞乱Visual Studio加载项API,试图看看我想做的事情是否可行。 我现在正在做的一件事是:
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
_applicationObject.Events.DebuggerEvents.OnExceptionThrown += DebuggerEvents_OnExceptionThrown;
handled = false;
if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if(commandName == "MyAddin1.Connect.MyAddin1")
{
handled = true;
return;
}
}
}
void DebuggerEvents_OnExceptionThrown(string ExceptionType, string Name, int Code, string Description, ref dbgExceptionAction ExceptionAction)
{
//how to get line number here?
}
理想情况下,我希望能够在被调试的程序抛出异常时获取当前函数和行号。 这可能吗?
这些信息显然已从调试信息中解除。 因此,它并不总是可用,我想这就是为什么StackFrames
对象在这种情况下不实现它是有道理的。
无论如何,要获得包含文件和行号信息(以及IL偏移等)的堆栈跟踪,您必须在调试应用程序的上下文中动态执行代码。 您可以使用GetExpression
执行此操作。
综上所述:
var tmp = dte.Debugger.GetExpression(
"new System.Diagnostics.StackTrace(true).ToString();", true);
这将返回一个包含堆栈跟踪的字符串,包括文件和行号......但是,您必须解析此返回的字符串以实际使用它,并且我认为这比更常用的方法慢得多
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.