Monday, February 9, 2015

What does it mean %* in batch file

%*will return the remainder of the command line starting at the first command line argument (in Windows NT 4, %* also includes all leading spaces)

see Command line parameters

When would you like to use it?One scenario is when you want first to check if util exists and then invoke it with
parameters passed to batch file

Batch file build.cmd
@ECHO OFF
setlocal

set PSakeVersion="4.3.1.0"
set PackagesRoot=%~dp0\..\Source\packages

set PSake=%PackagesRoot%\psake.%PSakeVersion%\tools\psake.cmd
if defined NuGet (
    set NuGet="-nuget %NuGet%"
)

rem check if PSake is downloaded
if not exist %PSake% (
   echo Unable to download PSake using nuget
   goto :EOF
)

echo Invoking PSake build...

%PSake% %~dp0\build.ps1 -framework "4.0" %*


calling batch.cmd
call .\Build\build.cmd PublishBuild -parameters "@{projectName='%ProjectName%';slnName='%SlnName%';platform='%BuildPlatform%';buildConfiguration='%BuildConfiguration%';xsBuildLabel='%system.build.number%';tfExePath='%TFExe%';TeamProjectCollection='$TeamProjectCollection%IsPreRelease%'}" -properties "@{nugetExePath='%env.NuGet%';msbuildLogger='%MSBuildLogger%'}"

It first check if PSake is installed and then run

%PSake% %~dp0\build.ps1 -framework "4.0" @{projectName='%ProjectName%';slnName='%SlnName%';platform='%BuildPlatform%';buildConfiguration='%BuildConfiguration%';xsBuildLabel='%system.build.number%';tfExePath='%TFExe%';TeamProjectCollection='$TeamProjectCollection%IsPreRelease%'}" -properties "@{nugetExePath='%env.NuGet%';msbuildLogger='%MSBuildLogger%'}

No comments:

Post a Comment