Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Grunt from Visual Studio post build event command line

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.

like image 601
Reedling78 Avatar asked Jun 23 '13 01:06

Reedling78


2 Answers

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

like image 181
Mike Pugh Avatar answered Sep 20 '22 08:09

Mike Pugh


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.

like image 39
Miguel Avatar answered Sep 19 '22 08:09

Miguel