Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Script for packaging and deployment of ASP.NET applications to IIS via Web Deploment Tools
Properties {
$Build_dir = Split-Path $psake.build_script_file
$Packages_dir = Join-Path $build_dir 'Packages'
$MsDeploy_dir = Join-Path $env:ProgramFiles 'IIS\Microsoft Web Deploy'
$SiteName = ''
$Package = "$"
$Dest = ''
$UserName = 'IIS User Name'
$Pwd = 'Secret Password'
Task Deploy {
Deploy-Package "$build_dir\Web\Web.csproj" Release $Package $Dest $SiteName $UserName $Pwd
function Deploy-Package {
param($Project, $Configuration, $PkgLocation, $DestServer, $SiteName, $UserName, $Password)
Write-Host Cleaning project files -ForegroundColor Cyan
Exec { MsBuild $Project /t:Clean /p:Configuration=$Configuration /v:q }
Write-Host "Staring building project $Project" -ForegroundColor Cyan
Exec { MsBuild $Project /t:Build /p:Configuration=$Configuration /v:q }
Write-Host "Starting packaging project $Project" -ForegroundColor Cyan
Exec { MsBuild $Project /t:Package /p:Configuration=$Configuration /p:PackageLocation=$PkgLocation /v:m }
Write-Host "Starting deployment site $SiteName to $DestServer" -ForegroundColor Cyan
$serverUrl = "https://${DestServer}:8172/msdeploy.axd?site=$SiteName"
$dest = "auto,computerName=$serverUrl,username=$UserName,password=$Password,authtype=basic"
Exec { & $MsDeploy_Dir\MsDeploy -verb:sync -source:package=$PkgLocation -dest:$dest -allowUntrusted }

rarous commented Feb 8, 2011


Great stuff

How would you deal wih a space in the source path i.e. $build_dir\deploy this\web


rarous commented Jun 3, 2012

It is quoted, it should just work.

Unfortunately msdeploy doesn't handle spaces in path when invoked from powershell even though Exec command tries to quote them. I tried many thinkable solutions how to escape/quote paths with space, but I had to use this nasty solution to workaround the problem:

Exec { cmd.exe /C $("msdeploy.exe -verb:sync -source:contentPath="{0}" -dest:package="{1}\{2}.zip"" -f $destinationDir, $destinationBackupDir, $backupFileName ) }

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