ligershark/psbuild

Arguments with spaces are not handled

Arithmomaniac opened this issue · 7 comments

$svnToolFolder = "C:\Program Files\TortoiseSVN\bin\"
$msbuildProperties = @{'SVNToolFolder'=$svnToolFolder;}
Invoke-MSBuild $slnFile -properties $msbuildProperties

As the point of the hashtable is to abstract away the command line, $svnToolFolder should automatically handle arguments with spaces. But this is what I see:

VERBOSE: Performing the operation "Invoke-MSBuild" on target "
msbuild.exe ..\Solutions\MySoliton.sln /p:SVNToolFolder=C:\Program Files\TortoiseSVN\bin\ [...]

@Arithmomaniac thanks for the issue, I agree it should be fixed. I've marked it as Approved.

I think I know how to fix it. When calling msbuild.exe we should use a pattern like what I'm using at https://github.com/sayedihashimi/publish-module/blob/master/package-downloader.psm1#L46. Here is the function

function Execute-CommandString{
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)]
        [string[]]$command,

        [switch]
        $ignoreExitCode
    )
    process{
        foreach($cmdToExec in $command){
            'Executing command [{0}]' -f $cmdToExec | Write-Verbose
            cmd.exe /D /C $cmdToExec

            if(-not $ignoreExitCode -and ($LASTEXITCODE -ne 0)){
                $msg = ('The command [{0}] exited with code [{1}]' -f $cmdToExec, $LASTEXITCODE)
                throw $msg
            }
        }
    }
}

OK turns out the fix was simpler than I thought. I've updated the module in the dev branch. Can you try it and re open if you still have issues?

What if there's an apostrophe inside the string argument? With this method, you should have logic to escape that too.

Thanks now that I'm thinking more here's your idea 💡 with some others.

  • Add quotes if not already quoted
  • Add a global setting which is true by default to enable
  • Add a parameter to Invoke-MSBuild

Hi @Arithmomaniac I have made the changes outlined in the commit aacb74f. Could you review and let me know if this looks better? Will close for now.

Looks like this broke some existing builds, see #54.
I've disabled it globally and released. You can enable with the global option EnablePropertyQuoting.

Should be fixed after the updates