最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Debugging Javascript in Visual Studio (or other JS debugger) - Stack Overflow

programmeradmin2浏览0评论

I have a .js file that normally gets executed by cscript.exe (i.e. is not run in the browser and cannot be run there).

I know, that I can feed cscript.exe the //X parameter in order to get asked for a debugger to choose. Ok. That's fine.

I select "Visual Studio 2005 Debugger", IDE es up, execution stops on the first line. Fine.

Script terminates (or I terminate it), I edit something and want to debug it again.

Simple thought would be just to hit F5 and run the debugger again. But this doesn't work. VS just tells me that it couldn't find any debugging symbols in cscript.exe:

What now? Starting cscript.exe from the mand line again for each debug run is quite cumbersome in my opinion.

Is there a way to simply debug the script with VS? Also hints for other debugging tools would be appreciated.


Edit:
The answer of t0nyh0 is pretty close. I create a dummy console application, pile and the debugger es up. However, two things are not perfect

  1. cscript.exe always asks for the debugger to use (which instance of VS).
    Could this be overe by specifying a certain debugger instance directly in the mand line?

  2. In order to fire a post-build event, there have to be some modifications in the sources. Currently, I simply add/delete a blank line to trigger building of my dummy project.
    Is there a way to always execute the post-build script, even if nothing has changed?

I have a .js file that normally gets executed by cscript.exe (i.e. is not run in the browser and cannot be run there).

I know, that I can feed cscript.exe the //X parameter in order to get asked for a debugger to choose. Ok. That's fine.

I select "Visual Studio 2005 Debugger", IDE es up, execution stops on the first line. Fine.

Script terminates (or I terminate it), I edit something and want to debug it again.

Simple thought would be just to hit F5 and run the debugger again. But this doesn't work. VS just tells me that it couldn't find any debugging symbols in cscript.exe:

What now? Starting cscript.exe from the mand line again for each debug run is quite cumbersome in my opinion.

Is there a way to simply debug the script with VS? Also hints for other debugging tools would be appreciated.


Edit:
The answer of t0nyh0 is pretty close. I create a dummy console application, pile and the debugger es up. However, two things are not perfect

  1. cscript.exe always asks for the debugger to use (which instance of VS).
    Could this be overe by specifying a certain debugger instance directly in the mand line?

  2. In order to fire a post-build event, there have to be some modifications in the sources. Currently, I simply add/delete a blank line to trigger building of my dummy project.
    Is there a way to always execute the post-build script, even if nothing has changed?

Share Improve this question edited May 23, 2017 at 12:07 CommunityBot 11 silver badge asked Feb 16, 2012 at 13:06 eckeseckes 67.3k31 gold badges176 silver badges206 bronze badges 1
  • With regards to 2. on the Build Events tab in Visual Studio, you have different options when to run Post Build events. At least in VS 2010, your options are "Always", "On successful build" and "When the build updates the project output". Not sure if it's the same for 2005 or not. – BryanJ Commented Mar 16, 2012 at 11:31
Add a ment  | 

4 Answers 4

Reset to default 2 +100

There might not be a way to attach the debugger to cscript.exe itself, but you may be able to create a post-build event that runs a batch file that executes the cscript.exe //x myScript.js mand so that every time you build, it executes for you automatically.

See this for more information on post-build events: http://msdn.microsoft./en-us/library/ke5z92ks(v=vs.80).aspx

While not a debugger tool, you should consider using a JavaScript testing framework for Visual Studio, such as Chutzpah, which will most likely make your life a lot easier.

Along with standard browser debugging tools (Firebug or Chrome Inspector), I've found that's all I usually need to build clean, tested, mostly-bug-free JavaScript code.

I don't have cscript at hand, but I think you can try to attach VS to the process manually.

After you start up your js using cscript.exe //x myScript.js, click "Debug - Attach to Process", find your cscript.exe process and attach to it.

I forget if VS2005 has this function but VS2008 and VS2010 do.

It is the native debug action that VS takes to debug (attach to the running process). If this doesn't work, I don't think you can do this using Visual Studio.

Best Javascript Debugger is Rhino Debugger See http://www.mozilla/rhino/debugger.html . it is open source and you can get the source code of the Debugger GUI. you can customise it as you wish :-) .

发布评论

评论列表(0)

  1. 暂无评论