我试图在不使用Visual Studio的情况下创建侧边栏小工具。我一直在寻找调试它们的方法,但是一切都说Visual Studio JIT调试器是唯一的方法。
没有人能够在没有Visual Studio的情况下调试侧边栏小工具吗?
最佳答案
多年以来,我一直没有使用Visual Studio来处理小工具。没有它,您可以通过几种方法来调试小工具,只是没有那么广泛。例如,没有适当的调试器附加到进程中,就不能使用debugger;
命令。您可以使用DebugView之类的程序来捕获 System.Debug.outputString()
方法输出的消息:
function test ()
{
System.Debug.outputString("Hello, I'm a debug message");
}
这使您可以在代码的某些阶段输出变量转储和其他有用的信息,因此您可以随意跟踪它。
或者,您可以使用
window.prompt()
滚动显示自己的调试/脚本停止消息。小工具禁用了alert()
,并且confirm()
被覆盖以始终返回true,但是它们必须忽略了prompt()
。function test ()
{
// execute some code
window.prompt(someVarToOutput, JSON.stringify(someObjectToExamine));
// execute some more code
}
如果要在代码执行期间检查对象的状态,
JSON.stringify()
方法确实可以提供帮助。除了
window.prompt
,您还可以使用VBScript MsgBox()
函数:window.execScript( //- Add MsgBox functionality for displaying error messages
'Function vbsMsgBox (prompt, buttons, title)\r\n'
+ ' vbsMsgBox = MsgBox(prompt, buttons, title)\r\n'
+ 'End Function', "vbscript"
);
vbsMsgBox("Some output message", 16, "Your Gadget Name");
最后,您可以使用
window.onerror
事件处理程序使用脚本捕获所有错误。function window.onerror (msg, file, line)
{
// Using MsgBox
var ErrorMsg = 'An error has occurred'+(line&&file?' in '+file+' on line '+line:'')+'. The message returned was:\r\n\r\n'+ msg + '\r\n\r\nIf the error persists, please report it.';
vbsMsgBox(ErrorMsg, 16, "Your Gadget Name");
// Using System.Debug.outputString
System.Debug.outputString(line+": "+msg);
// Using window.prompt
window.prompt(file+": "+line, msg);
// Cancel the default action
return true;
}
window.onerror
事件甚至允许您输出发生错误的行号和文件(仅适用于IE8)。祝您调试顺利,请记住在发布小工具时不要离开任何window.prompts或MsgBoxes!
关于windows-desktop-gadgets - 在没有Visual Studio的情况下调试Windows边栏小工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2284101/