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.
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).
If you had Visual Studio open and then:
The build will simply fail with the "exited with code 9009" message. (Meaning "I don't know what grunt command is")
To resolve this situation just close visual studio and reopen it (as @longda mentioned on his comment) and everything will work just fine.
I'm using VS 2013 Premium and latest version of npm/grunt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With