Skip to content

Instantly share code, notes, and snippets.

@mrahhal
Created December 28, 2016 17:30
Show Gist options
  • Save mrahhal/5d2016c4b4f1ce175b170f08abc190e9 to your computer and use it in GitHub Desktop.
Save mrahhal/5d2016c4b4f1ce175b170f08abc190e9 to your computer and use it in GitHub Desktop.
Deploying an Asp.NetCore website using msdeploy.
$webdeploy = "C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$location = Get-Location | Select-Object $_.Path
$packOutput = Join-Path $location "bin\Release\netcoreapp1.1\publish"
$app_offline = Join-Path $location "app_offline-template.htm"
$iisApp = "..."
$computerName = "..."
$username = "..."
$password = "..."
function DeletePublishFolder()
{
if (Test-Path $packOutput)
{
WriteInfo "Removing publish folder..."
Remove-Item -Force -Recurse $packOutput
}
}
function RunNpm()
{
npm run build:prod
if ($LASTEXITCODE -ne 0)
{
WriteFailed "Failed with code $LASTEXITCODE. Exiting..."
Exit
}
}
function Publish()
{
dotnet publish -c Release
WriteSuccess "Published!"
}
function Deploy()
{
& $webdeploy -verb:sync -source:contentPath=$app_offline -dest:contentPath=$iisApp/app_offline.htm,ComputerName=$computerName,UserName=$username,Password=$password,IncludeAcls="False",AuthType="Basic" -retryAttempts:5 -allowUntrusted
if ($LASTEXITCODE -ne 0)
{
WriteFailed "Failed with code $LASTEXITCODE. Exiting..."
Exit
}
& $webdeploy -verb:sync -source:IisApp=$packOutput -dest:IisApp=$iisApp,ComputerName=$computerName,UserName=$username,Password=$password,IncludeAcls="False",AuthType="Basic" -enableRule:DoNotDeleteRule -disablerule:BackupRule -enableLink:contentLibExtension -retryAttempts:5 -allowUntrusted
if ($LASTEXITCODE -ne 0)
{
WriteFailed "Failed with code $LASTEXITCODE. Exiting..."
Exit
}
& $webdeploy -verb:delete -dest:contentPath=$iisApp/app_offline.htm,ComputerName=$computerName,UserName=$username,Password=$password,IncludeAcls="False",AuthType="Basic" -retryAttempts:5 -allowUntrusted
if ($LASTEXITCODE -ne 0)
{
WriteFailed "Failed with code $LASTEXITCODE. Exiting..."
Exit
}
WriteSuccess "Deployment succeeded!"
}
function WriteFailed($text)
{
Write-Host $text -ForegroundColor Red
}
function WriteInfo($text)
{
Write-Host $text -ForegroundColor Cyan
}
function WriteSuccess($text)
{
Write-Host $text -ForegroundColor Green
}
# -----------
DeletePublishFolder
RunNpm
Publish
Deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment