Skip to content

Instantly share code, notes, and snippets.

@SarahBourgeois
Created October 6, 2017 12:00
Show Gist options
  • Save SarahBourgeois/40b9b9b1c4051f737765d493a97ec698 to your computer and use it in GitHub Desktop.
Save SarahBourgeois/40b9b9b1c4051f737765d493a97ec698 to your computer and use it in GitHub Desktop.
Powershell script to deploy automatically a website on IIS (Internet Information Services) thanks to Msbuild and MsDeploy
# ====================================================
# NAME : deploy-website-iis.ps1
# AUTHOR : Bourgeois Sarah
# Date : à5/10/2017
# VERSION 1.0.0
# COMMENTS : Automatically deploy dotnet website on IIS
# ======================================================
$WEBSITE_PATH = '<your visual studio solution web site path here'
$BUILD_WEBSITE = '<path msbuild>/msbuild.exe <path .csproj file of your website>/yourfile.csproj /T:Package /P:Configuration=Release'
# stop IIS and Sql server
cmd /c 'iisrest /stop'
if(-not $?)
{
'could not stop IIS.';
}`
cmd /c 'net stop mssqlserver'
if(-not $?)
{
'could not stop SQL Server.';
}`
#pull your project before build
Write-Output 'Pull git project...'
Invoke-Expression $WEBSITE_PATH
cmd /c 'git pull'
if(-not $?)
{
'could not pull the project from git.';
}
# build project
Write-Output 'Petclinic is building...'
cmd /c $BUILD_WEBSITE
if(-not $?)
{
'could not build the project. Check the stacktrace.';
exit
}
# Import package create
cmd /c '<path msDeploy>\msdeploy.exe -verb:sync -source:package=<path of your project>\obj\Release\Package\DotNetPetClinic.zip -dest:auto'
if(-not $?)
{
'could not import the project.';
exit
}
#restart IIS app pool to run the website
cmd /c 'C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:<NAME OF YOUR WEBSITE APP POOL'
if(-not $?)
{
'error during restarting the appPool.';
exit
}`
# Restart IIS and SQL Sever Instance
cmd /c 'net start mssqlserver'
if(-not $?)
{
'could not restart Sql Server.';
}`
cmd /c 'iisreset /start'
if(-not $?)
{
'could not restart Sql Server.';
}
#######################
# Additionnal config
#######################
###############
# appool config
################
# if you need to configure your app pool version do this after build :
#cmd /c 'C:\Windows\System32\inetsrv\appcmd.exe set apppool /apppool.name:DefaultAppPool /managedRuntimeVersion:v4.5'
# and this after import package
#cmd /c 'C:\Windows\System32\inetsrv\appcmd.exe set apppool /apppool.name:DefaultAppPool /managedRuntimeVersion:v4.0'
###########
# BDD IMPORT
##############
# to import your local bdd into iis : create folder name app date with your .mdf database
#Copy-Item -Path <path of your app data folder>\App_Data -Destination C:\inetpub\wwwroot\<name of your website> -Recurse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment