21

So I have a command I want to run which looks like the following:

for /r %n in ("*.vdproj") do "C:/Program Files/Microsoft
 Visual Studio 10.0/Common7/IDE/devenv.exe" %n /build "BuildServer"

It seems to work in that it runs devenv on each .vdproj file; however, it seems to run them in parallel and immediately return. This is a problem; I need to wait until they are all finished before the next step in the .bat file runs. How can I either

1- Get for to 'wait' on each devenv to finish before running the next one

or

2- Wait until devenv.exe is all done before moving on afterwards?

Joey
  • 344,408
  • 85
  • 689
  • 683
GWLlosa
  • 23,995
  • 17
  • 79
  • 116
  • (don't you want %n%, or is it even %%n%% ?) else 2 things. Are you sure devenv.exe is actually doing something OR is it failing immediately, giving you the impression that it is running your list in parallel? i.e. Did you try executing just one iteration of the for loop (without the forloop) from the commandline, filling in known, existing dir/file values for your %n? 2. use the processes tab on the task manager, sorted by process name, to see if you see a mess of devenv.exe's running on your system. That would prove that my question #1 is not relevant. Good luck. – shellter May 02 '12 at 16:07
  • If I look at the task manager, I see a whole slew of Devenv.exe's running, and they do seem to run to completion and stop eventually. – GWLlosa May 02 '12 at 16:49

2 Answers2

49

The trick is to use devenv.com instead of devenv.exe. devenv.com will return output to the console and achieve exactly the desired result.

GWLlosa
  • 23,995
  • 17
  • 79
  • 116
5

Invoke devenv.exe using start, e.g.

start /wait "" "C:/Program Files/Microsoft Visual Studio 10.0/Common7/IDE/devenv.exe" %n /build "BuildServer"

Use start /? for usage.

Cameron
  • 96,106
  • 25
  • 196
  • 225
sorpigal
  • 25,504
  • 8
  • 57
  • 75
  • I tried that, but it still returned immediately... not sure if its because devenv does its own launch-on-seperate thread and return game or something, but start /wait /B did not work at all. – GWLlosa May 02 '12 at 15:03
  • Interesting. Another workaround, off the top of my head, is to bypass devenv and invoke msbuild directly instead. – sorpigal May 02 '12 at 15:05
  • 1
    Unfortunately, this IS the workaround to msbuild... MSBuild.exe can't handle .vdproj (installer/merge module) projects directly. – GWLlosa May 02 '12 at 15:09
  • Also, a few years later, MSBuild doesn't support C# 6.0 features either. – Wai Ha Lee Jun 10 '16 at 08:47
  • 1
    This works! This works! (and the .com doesn't, at least for me on Windows 10). But -- you have to pass an empty title string to `start`, otherwise it [thinks the first quoted parameter is the title](http://stackoverflow.com/questions/154075/using-the-dos-start-command-with-parameters-passed-to-the-started-program) to use for the window and does weird things. I'm suggesting an edit. – Cameron Jul 05 '16 at 20:48
  • 1
    Also, `"%VS100COMNTOOLS%"\..\IDE\devenv.exe` can be used as the path for portability regardless of where VS was installed (and the bitness of the OS). – Cameron Jul 05 '16 at 20:51