Automated Site Setup Scripts (Sitecore / Umbraco)

We wanted a simple way to get a new environment set up on a developer machine, but without the hassle of Virtual Machines.

Enter, Microsoft’s appcmd.

This lets you manipulate IIS7 via command line calls. There is lots of documentation on the IIS site but it takes a while to figure out which commands you need to do everything to set up a site. So I’ve put together a selection of the useful commands below in a sample site setup script.

We save these as batch files (.bat) and put them in a shared folder.

Prerequisites:

  • You work on Windows using IIS7
  • (if Sitecore) You have all relevant Sitecore installation zips in a shared network folder
  • (if Umbraco) You use Nuget package to distribute Umbraco CMS (or you could do the zip thing)
  • You run sites locally with custom host name, using a shared DB
  • All team members setup sites in the same folder path e.g. c:work
  • You have admin rights on the local machine

Sample setup script:

Put this in a .bat file and save in a shared folder. Keep as many steps as required, and replace the relevant placeholders. To run, right click Run as Administrator.

@ECHO OFF

ECHO *** MUST BE RUN AS ADMIN - IF NOT PLEASE CLOSE AND RUN AGAIN, OTHERWISE: ***
PAUSE

ECHO *** CHECKING OUT FROM SVN ***

IF not exist c:PATH_TO_TRUNK svn checkout -q https://SVN_PATH_TO_TRUNK c:PATH_TO_TRUNK

ECHO *** EXTRACTING SITECORE ***

"C:Program Files-Zipz" x -y "PATH_TO_SITECORE_ZIPSSitecore 7.0 rev. 140120.zip" -oc:PATH_TO_TRUNK "Sitecore 7.0 rev. 140120Data" "Sitecore 7.0 rev. 140120Website"

ECHO *** RENAMING SITECORE ***

rename "c:PATH_TO_TRUNKSitecore 7.0 rev. 140120" www

ECHO *** COPY LICENSE ***

copy PATH_TO_LICENSElicense.xml c:PATH_TO_TRUNKwwwData

ECHO *** CREATING APP POOL ***

C:WindowsSystem32inetsrvappcmd add apppool /name:"APP_POOL_NAME" -managedRuntimeVersion:v4.0

ECHO *** CREATING SITE ***

C:WindowsSystem32inetsrvappcmd add site /name:"APP_POOL_NAME" /bindings:http://site.localhost:80 /physicalPath:"c:PATH_TO_TRUNKwwwWebsite" -applicationDefaults.applicationPool:APP_POOL_NAME

ECHO *** CREATING VIRTUAL DIRECTORIES ***

C:WindowsSystem32inetsrvappcmd add vdir /app.name:"APP_POOL_NAME/" /path:/siteAssets /physicalPath:c:PATH_TO_TRUNKsiteAssets

ECHO *** ADDING TO HOSTS FILE ***

find /c "	site.localhost" c:windowssystem32driversetchosts
if %errorlevel% equ 1 goto notfound
echo Already there
goto done
:notfound
ECHO 127.0.0.1	site.localhost >> c:windowssystem32driversetchosts
goto done
:done
  
ECHO *** BUILDING SOLUTION ***

C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe c:PATH_TO_TRUNKsrcSite.sln /verbosity:quiet

ECHO *** OPENING SITE ***

start http://site.localhost/

PAUSE

Hope that’s helpful to someone!

Source: Andrew Lansdowne
Read and comment on original post: Automated Site Setup Scripts (Sitecore / Umbraco)