On a whim, in order to learn PowerShell, which I know I'm woefully behind on, I decided to write a super simple script to use MSBuild to clean a bunch of solutions in code, then build them with a certain set of arguments. Here's the script:
$sourceDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$cleanArgs = '/t:clean /verbosity:q /nologo /P:Configuration=Debug'
$buildArgs = '/verbosity:q /nologo /P:Platform="Any CPU";Configuration=Debug'
$solutions = @("asdf.sln","qwer.sln","zxcv.sln","yuio.sln","hjkl.sln","nm.sln")
function buildWithArgs([string[]]$solutionsToBuild = @(), [string]$args = 'default')
{
Write-Host args: $args
foreach($sln in $solutionsToBuild)
{
& $env:WINDIR\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe "$sourceDir\$sln $args" | Out-Default
}
}
buildWithArgs $solutions $buildArgs
buildWithArgs $solutions $cleanArgs
Now, my problem is that the function "buildWithArgs" doesn't respect the $args parameter, which is always empty when I run or debug the script, no matter what I pass in. The $solutionsToBuild parameter works flawlessly, however. Do I have improper syntax? Even if it were the case that my $cleanArgs string was somehow improperly formatted or not escaped, I can't even make the function work with simple strings like "asdf", as $args is always empty when I run it. Thanks for any help you can provide to what is assuredly some small, silly error!