Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments with spaces are not handled #49

Closed
Arithmomaniac opened this issue Mar 2, 2015 · 7 comments
Closed

Arguments with spaces are not handled #49

Arithmomaniac opened this issue Mar 2, 2015 · 7 comments

Comments

@Arithmomaniac
Copy link

$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 Arithmomaniac changed the title Arguments are not wrapped in quotation marks Arguments with spaces are not handled Mar 2, 2015
@sayedihashimi
Copy link
Member

@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
            }
        }
    }
}

@sayedihashimi
Copy link
Member

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?

@Arithmomaniac
Copy link
Author

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

@sayedihashimi
Copy link
Member

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

@sayedihashimi
Copy link
Member

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.

@sayedihashimi
Copy link
Member

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

@sayedihashimi
Copy link
Member

Should be fixed after the updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants