简体   繁体   中英

Launch long running cmd as pre-build event in Visual Studio

I'm trying to launch a grunt process that will watch for .js file changes and transpile them into one file using grunt tasks. I can run it manually all day long, but I want to make it a pre-build so when a new dev gets the solution, building will launch the watcher. The problem (as you may have guessed) is that the grunt process stays running, so as a pre-build event, it never continues the build. I thought that using start would be asynchronous and would launch it without VS waiting on it to complete to continue the build, but I was mistaken. So, currently, my pre-build event is

cmd /c start $(SolutionDir)ProjectName.Web\\run-grunt.cmd $(SolutionDir)

and run-grunt.cmd looks like

cd %1ProjectName.Web
grunt

This works but hangs until I close the cmd window which defeats the whole purpose. So, two questions:

  1. Is this the wrong way to get this watcher kicked off?
  2. Is there a way to structure these such that VS will launch the cmd and then resume the build without waiting for a return?

Have you tried setting your pre-build event to simply run a batch file that executes your current pre-build event? It seems like it will work because the batch file that Visual Studio executes will actually complete, leaving another command window in its wake.

I tested my theory with two batch files:

test1.bat

call "cmd /C start test2.bat"
echo test1

test2.bat

echo test2
pause

If you're still needing some parts of the grunt task to execute pre-build, you can break them out into separate tasks, so your pre-build event may end up looking like this:

cd $(SolutionDir)ProjectName.Web\
grunt build
grunt-watch.bat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM