Running Grunt from Visual Studio post build event command line

Reedling78 picture Reedling78 · Jun 23, 2013 · Viewed 12.1k times · Source

I've attempted to do this both in Visual Studio 2010 and Visual Studio 2012. If my Gruntfile.js file is in the root of my project I can run the "grunt" command from the post build event command line and it runs without a problem.

grunt or grunt.cmd

But if it's in a sub directory

$(ProjectDir)Public\grunt or $(ProjectDir)Public\grunt.cmd

It gives me this error

The command "c:\web\Public\grunt.cmd" exited with code 9009.

I've been researching this but I'm not finding any much help out there. I did find in the grunt documentation that I need to use "grunt.cmd" instead of just calling "grunt" but thats not helping me much.

Answer

Mike Pugh picture Mike Pugh · Aug 29, 2013

What's happening is you're specifying an exact path for grunt, which doesn't actually reside at $(ProjectDir)Public\. When you're in that directory on a command prompt and type grunt, it executes because you've set your path environment variable to include the directory where grunt lives.

Luckily the post build commands in VS act like a command window, so you can put this in your post build commands:

CD $(ProjectDir)Public\
grunt

And that should work (assuming a default grunt task is defined).