Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Javascript in Visual Studio (or other JS debugger)

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 comes 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: screenshot

What now? Starting cscript.exe from the command 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, compile and the debugger comes up. However, two things are not perfect

  1. cscript.exe always asks for the debugger to use (which instance of VS).
    Could this be overcome by specifying a certain debugger instance directly in the command 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?

like image 681
eckes Avatar asked Feb 16 '12 13:02

eckes


1 Answers

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 command so that every time you build, it executes for you automatically.

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

like image 75
t0nyh0 Avatar answered Sep 30 '22 15:09

t0nyh0