Question

So, I want to be able to build an arbitrary number of VS solutions using a batch script. I would want the script to search for the given project names, and pass their filepaths to the VS CLI.The format would be along the lines of:

build_slns (debug|release) [proj1] [proj2] ... [projN]

The first arg would be the configuration, and all subsequent args would be project names. The part I'm having trouble with, is that these projects will all be in different subdirectories of my base code directory. So an example would be something like this:

build_slns debug foo bar foobar

And the .slns I want to build would be located like so:

Code\foo\foo.sln
Code\foo\bar\bar.sln
Code\foobar\foobar.sln

I believe I'll want to use FOR /F, but I'm just not familiar enough with batch to get it working the way I want it to. Any guidance here is greatly appreciated.

Was it helpful?

Solution

Something like this should work

@echo off
setlocal
::change the definition of cmd and root as needed
set cmd="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
set root="d:\utils"

:loop
if "%~2" equ "" exit /b
echo Searching for %2
for /f "eol=: delims=" %%F in ('dir /b /s "%root%\%2.sln"') do (
  echo Building %%F
  %cmd% "%%F" /build %1
)
shift /2
goto :loop
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top