简体   繁体   中英

How to prevent powershell merging msbuild properties?

I have this powershell script

$msbuildSettings="/p:Configuration=Release /p:VisualStudioVersion=12.0";
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe ..\Sol.sln /t:"Clean;Admin" $msbuildSettings

Which causes this error

The specified solution configuration "Release /p:VisualStudioVersion=12.0|Mixed Platforms" is invalid.

Msbuild thinks

/p:Configuration=Release /p:VisualStudioVersion=12.0

is one property.

If I do not use the variable msbuildsettings, the build works, ie

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe ..\WeConnectSol.sln /t:"Clean;WeConnectAdmin" /p:Configuration=Release /p:VisualStudioVersion=12.0

How do I tell powershell not to merge the properties?

First, I would recommend you to use Join-Path and the $env:windir variable to determine the msbuild path:

$msbuild = Join-Path $env:windir 'Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe'

Also, I would use an array to define the parameters:

$parameters = @(
    '..\Sol.sln', 
    '/t:"Clean;Admin"', 
    '/p:Configuration=Release', 
    '/p:VisualStudioVersion=12.0')

And finally pass the parameters using splatting :

& $msbuild @parameters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM