Skip to content

Instantly share code, notes, and snippets.

@dphoebus
Forked from rarous/Deploy.ps1
Created February 23, 2016 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dphoebus/6133786592b83b028ea1 to your computer and use it in GitHub Desktop.
Save dphoebus/6133786592b83b028ea1 to your computer and use it in GitHub Desktop.
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 = '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 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment