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:

  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.

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

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top