Here is what I consider a better powershell script to execute msbuild. What I 
really like about this script is that it finds msbuild on its own and sets a 
number of default values that can be overridden at call-time. This script is 
really good for command line usage. If I just needed to automate the call of 
msbuild with hard coded values in another powershell script then I wouldn't use 
this script. In this case I would just call msbuild directly with the hard 
coded values.

#-----------------------------------------------------
# build.ps1
[CmdletBinding(PositionalBinding = $false)]
param (
    [ValidateSet('Build', 'Clean', 'Rebuild')]
    [string]
    $Target = 'Build',

    [ValidateSet('Release', 'Debug')]
    [string]
    $Configuration = 'Release',

    [ValidateSet('Mixed Platforms', 'Any CPU', 'x64', 'x86')]
    [string] $Platform = 'Mixed Platforms',

    [Parameter(ValueFromRemainingArguments = $true)]
    [Alias('Args')]
    [string[]] $ArgumentList
)

$MSBuildCmd = $(
    Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0 |
    Select-Object -ExpandProperty MSBuildToolsPath |
    Join-Path -ChildPath MSBuild.exe
)

$MSBuildArgs = @(
    , '/fl'
    , '/flp:PerformanceSummary;Verbosity=normal'
    , '/v:normal'
    , '/tv:4.0'
    , "/p:Configuration=${Configuration}"
    , "/p:Platform=${Platform}"
    , "/t:${Target}"
)

& $MSBuildCmd $MSBuildArgs $ArgumentList


Edwin G. Castro
Software Developer - Staff
Digital Channels
Fiserv
Office: 503-746-0643
Fax: 503-617-0291
www.fiserv.com
Please consider the environment before printing this e-mail

> -----Original Message-----
> From: john.burak [mailto:john.bu...@telvent.com]
> Sent: Thursday, May 10, 2012 2:36 PM
> To: wix-users@lists.sourceforge.net
> Subject: Re: [WiX-users] using wix with powershell
> 
> I've done it and it works fine.  One tricky thing was working with 
> PowerShell's
> parsing modes to get the arguments passed-in correctly (notice the back-tick-
> escaped double quotes in the $msBuildArgs parameter,  below).
> If you manually use Candle/Light you have to worry about compiling fragments
> ahead of time and passing them into Light (ugh).  It's much easier to set up a
> Visual Studio project and call msbuild on it. :)
> 
> Here is a stripped down version of the script I call to compile .sln files.
> I haven't tested this exact code, but it should get you in the right 
> direction.  I'd
> call it with a command somewhat like /c:\path\MyInstaller.sln |
> c:\buildTools\compileWixSolution.ps1/ , assuming you save it to
> "compileWixSolution.ps1" and the defaults for the last two parameters are
> correct.  You can also pipe in multiple solutions, which I do.  It will 
> create a nice
> log file if msbuild had errors compiling the project.
> 
> param
> (
>     [parameter(
>         Mandatory=$true,
>         ValueFromPipeline=$true)]
>     [System.IO.FileInfo]
>     # The solution to compile
>     $file,
> 
>     [System.IO.FileInfo]
>     # The handle to the MSBuild executable.
>     $msBuild =
> "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe",
> 
>     [String]
>     $msbuildArgs = "`"$file`" /target:rebuild
> `"/property:Configuration=Debug;Platform=x86`" /v:minimal /maxcpucount:2"
> )
> Process
> {
>     $log = ("" + $file.FullName + "_msbuild.log")
>     if(Test-Path $log){ Remove-Item $log } # Remove old, previous log file.
> 
>     # Run msbuild
>     $process = Start-Process $msBuild -ArgumentList $msbuildArgs -Wait -
> PassThru -NoNewWindow -RedirectStandardOutput $log
>     if($process.ExitCode)
>               { Write-Error "Error from $msBuild.  See $log" } }
> 
> 
> Edwin G. Castro wrote
> >
> > Are you trying to build a wix project? The easiest way to do this is
> > to simply call
> >
> > msbuild solution.sln
> >
> > Or perhaps
> >
> > msbuild project.wixproj
> >
> > Passing the usual command line arguments to msbuild.
> >
> > If you are truly looking to call candle.exe, light.exe, etc. then just
> > call them with the appropriate arguments.
> >
> > What exactly is your goal?
> >
> >> -----Original Message-----
> >> From: Sean Farrow [mailto:sean.farrow@.co]
> >> Sent: Monday, May 07, 2012 7:29 PM
> >> To: wix-users@.sourceforge
> >> Subject: [WiX-users] using wix with powershell
> >>
> >> Hi All:
> >> Has anybody got any experience of automating wix from powershell,
> >> either from the standard interface or writing cmdlets.
> >> I'm looking to automate a build system.
> >> Any help appreciated.Regards
> >> Sean.
> >
> 
> 
> --
> View this message in context: http://windows-installer-xml-wix-
> toolset.687559.n2.nabble.com/using-wix-with-powershell-
> tp7537541p7548429.html
> Sent from the wix-users mailing list archive at Nabble.com.
> 
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and threat
> landscape has changed and how IT managers can respond. Discussions will
> include endpoint security, mobile security and the latest in malware threats.
> http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> WiX-users mailing list
> WiX-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wix-users
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to