Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Script for packaging and deployment of ASP.NET applications to IIS via Web Deploment Tools

View Deploy.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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 = 'www.example.com'
$Package = "$SiteName.zip"
$Dest = 'hosting.com'
$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 }
}
Owner

Prerequisites:

Great stuff

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

Owner
rarous commented

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
Something went wrong with that request. Please try again.