Sitecore Rocks, PowerShell and SVN

Rather than creating a new website from the Sitecore zipfile, I wanted to create a new Sitecore website based on the files we have in SVN. After the Sitecore Rocks demo on Sitecore Symposium Amsterdam, I decided to create something like that, using Rocks. 

To get started, I first needed to create a new task list. This can be done through the Sitecore Rocks extension in Visual Studio. It was fairly similar to the ‘Install Sitecore Website’ that comes with Sitecore Rocks, so I decided to copy that task list and change it for my needs. By going to ‘Manage Task Lists’ (under Sitecore->Task Lists->Manage Task Lists), right clicking on the task list and selecting ‘Open in Windows Explorer’ the path of all task lists is easily found.

I just copied the InstallSitecore task list, gave it a new name and edited the tasks.

First point of interest here is the *taskname*.tasklist.xml file. The value of the <name> node is very important, since this is what dictates which tasks get added to this list.

The XML files are the ‘layout’ of the tasks – they define the title, description and to which taskslist they belong to. They also contain the fields needed (if they are necessary). I just needed the fields which are in fieldtype ‘installationFolders’: 

  • Base folder
  • Project name
  • Project folder
  • Website folder
  • Database folder
  • Data folder

 

For my project, I came up with the following steps:

  • Create project folder
  • Create a new branch in SVN
  • Get the new branch from SVN
  • Switch the working copy to the new branch
  • Copy the licence files
  • Copy some files and folders that aren’t in SVN
  • Set Security
  • Build solution
  • Create IIS Site
  • Add Site to Host File
  • Install Sitecore Rocks
  • Warm Up
  • Open Sitecore

I won’t go into the ‘default’ Sitecore Rocks steps (in the InstallSitecore task), since they seem fairly straightforward. I did need to change the license file copying step – instead of having that in a field in Sitecore Rocks, I decided to just copy it from one of our development servers.

The whole project was actually a lot easier than expected. The only dependency is that I needed a client which allowed command-line scripts without input. I only had TortoiseSVN installed, which does need input, so I installed Slik SVN (http://sliksvn.com/en/download/) instead.

Create new branch

The only difficulty here is we need to check whether the branch exists beforehand. The rest is just copying and pasting of the trunk to a new location
$svnBranchRoot = https://location/of/your/branches/
$svnNewBranchName = $svnBranchRoot + $parameters[“projectName”]
$svnTrunk=https://location/of/your/trunk

#Check if branch exists
If(Test-Path $svnNewBranchName) {
Write-Host “Error: $svnNewBranchName already exists.”
Exit(-1)
}

#Create branch
svn copy $svnTrunk $svnNewBranchName -m “Created new branch $svnNewBranchName”

Get new branch from SVN

All I needed was 3 lines of code:

$svnTrunk=https://location/of/the/trunk
$folder = $parameters[“projectFolder”] + “\”
svn co $svnTrunk $folder

(co is just shorthand for checkout.)

If it doesn’t matter that input is needed, it can be done with TortoiseSVN as well, instead of the last line put this:
TortoiseProc.exe /command:checkout /url:$svnTrunk /path:$folder /closeonend:0

Note, if on either of the two commands you get an error, make sure the paths to their exe are added to the Environment Variables. Figuring this out took me a little while (and the help of my colleague @_shriroop_ )

This can be found under the properties of My Computer, Advanced System Settings, Environment Variables. I added mine to the system variable Path, but I don’t know what the recommended practice here is.

Switch the working copy

This is also as easy as it sounds:

$svnBranchRoot= https://location/of/your/branches/
$workingCopySVN = $svnBranchRoot + $parameters[“projectName”]
$workingCopyFileSystem = $parameters[“projectFolder”] + “\”

#Switch the working copy
svn switch $workingCopySVN $workingCopyFileSystem

Write-Output “Switched working copy”

Build solution

Lastly, I wanted to build the solution, since it needs to be built before the site can actually be called.
Here I’m just using msbuild:

$SlnFilePath = $parameters[“projectFolder”] + “\Product\Saga.Sitecore.sln”
msbuild $SlnFilePath /t:rebuild /p:Configuration=Debug /p:Platform=”any cpu”

I realize this could’ve been done a little more dynamic, for instance by adding a field where one can specify where the trunk is located, but I decided against it, since our trunk hasn’t had a location change since we put it in place.

Overall, it really surprised me how easy this was done. Comments on how things could’ve been done otherwise would be very welcome of course.