For command using devenv.exe runs too quickly
Asked Answered
S

2

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?

Schutzstaffel answered 2/5, 2012 at 14:44 Comment(2)
(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.Modify
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.Schutzstaffel
S
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.

Schutzstaffel answered 2/5, 2012 at 20:51 Comment(8)
What if it is a 64bit machine?Ponce
Then it is probably Program Files (x86).Schutzstaffel
I was referring to the fact that 64bit Windows does not run .com files.Ponce
Oh. That's a bigger problem I suppose. But can't you run .com files from a 32-bit cmd interface?Schutzstaffel
I believe com files can only be run via a virtual machine on Windows 64 bit machines.Ponce
@Petoj +1. I'm on 64bit W7 as well, and it works fine for me.Chapatti
Except that devenv.com appears not to work with the /Upgrade switch (it doesn't do anything at all, as far as I can tell).Levkas
devenv.com also sets ERRORLEVEL to 0 for successful builds, or a positive number for failed builds, which is essential for tracking success in build scripts.Banderilla
W
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.

Warthog answered 2/5, 2012 at 15:2 Comment(6)
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.Schutzstaffel
Interesting. Another workaround, off the top of my head, is to bypass devenv and invoke msbuild directly instead.Warthog
Unfortunately, this IS the workaround to msbuild... MSBuild.exe can't handle .vdproj (installer/merge module) projects directly.Schutzstaffel
Also, a few years later, MSBuild doesn't support C# 6.0 features either.Jodi
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 to use for the window and does weird things. I'm suggesting an edit.Levkas
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).Levkas

© 2022 - 2024 — McMap. All rights reserved.