15
votes

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.

4
Quick note for anyone finding this via google - I just ran into this issue and my path was setup correctly, but I had done so after Visual Studio was opened meaning the path updates were not available in Visual Studio. Closing all Visual Studio windows then re-opening the solution actually fixed my issue (just like you might do with a console window - could also re-source it too but that doesn't make sense for Visual Studio).longda
doh this just helped me, thanks @longda. .. close and reopen .."have you tried turning it off and on?" ..peter

4 Answers

13
votes

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).

3
votes

If you had Visual Studio open and then:

  1. Installed node package manager (npm) and grunt
  2. Then tried to run pre/post build commands including grunt command.

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.

3
votes

You can run as post build using task runner as shown below. Right click on the build --> bindings--> and then specify if you need it to run post or pre build

0
votes

Somewhat related, I had a weird issue that xcopy would not run after grunt, running them as a single command fixed it:

cd $(SolutionDir)..\App
grunt release && xcopy "$(SolutionDir)..\App\release" "$(TargetDir)Content\" /Y /E /S