Sitecore helix build and deploy done with PowerShell

Helix deployment without gulp dependancy.

This script was developed with the intention to eliminate gulp dependency from the deployment of our helix solutions. We need something that could be used dynamically across all solutions.

Calling MSBuild with a powershell script via the package manager console. You do not have to leave Visual Studio. The deployment process take a fraction of the time gulp does.

Me and my team have set up multiple helix solution from scratch based on habitat. See my co-worker’s blog for an guide regarding setting up a clean helix solution from scratch.

This post will only cover the build and deploy powershell script and how to implement it into helix. Structured in the following way:

  • prerequisite
  • install
  • usage
  • developer notes

Go to my github to see script and configuration files.


(1) IIS Management Script and Tools must be enabled from ‘turn windows features on or off’


(2) Nuget restore functionality:

To be able to run a nuget restore command you need the nuget command line interface. I went with v.4.7.1 and created a folder called C:\Program Files\Nuget CLI where i palced the exe.

The following instruction is taken from here:

1. Visit and select NuGet 3.3 or higher (2.8.6 is not compatible with Mono). The latest version is always recommended, and 4.1.0+ is required to publish packages to

2. Each download is the nuget.exe file directly. Instruct your browser to save the file to a folder of your choice. The file is not an installer; you won’t see anything if you run it directly from the browser.

3. Add the folder where you placed nuget.exe to your PATH environment variable to use the CLI tool from anywhere. Restart your command prompt applications or pc for the change to take effect.


Nuget restore functionality can be turned off by setting the boolean value to false in the build-and-deploy-configuration.json.

(3) Unicorn functionality:

To execute unicorn remotely with powershell, it is used a script from this blogpost. Script was modified to get the microCHAP.dll automtically from your project bin folder.

These two scripts was included in the serialization foundation project under /src/foundation/serialization/code/unicornsync/.

You can specifiy the script path in build-and-deploy-configuration.json.

(4) Set unrestricted executionpolicy for powershell

The package manager console in visual studio is a 32 bit version of powershell. 32 bit and 64 bit uses different execution policy and since we use the 32 bit, you need to target this.

You can use the package manager console to run the set execution policy command to ensure you are targeting the correct PowerShell.

Set-ExecutionPolicy Unrestricted
Get-ExecutionPolicy -List

(5) Ensure the required versions of nuget packages.

You need at least following versions:

  • 1.0.7 of Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  • 2.1.0 of Microsoft.Net.Compilers

You can probably use later versions also. I used 1.0.7 and 2.1.0. This will solve a lot of the locked .dll issues when running MSbuild.exe.


Step 1: Download script, configuration and nuget profile hosted on my github here.

Step 2: Determine which folder you want to store the script.

Copy build-and-deploy.ps1 to the directory. It should be in a universal place so you can access it on all your projects. I went with C:\Sitecoreprojects\powershell.

Step 3: Add reference to your nuget_profile.ps1.

To find the location of the nuget profile you need to type $profile in your package manager console in Visual Studio.


Default location is C:\Users\username\Documents\WindowsPowerShell\NuGet_profile.ps1

Add a reference to the build-and-deploy.ps1 script.


If there is no profile there at all. Create an empty file and name it NuGet_profile.ps1 or use the one from the github repository in step 1.

If there are any changes to the script used by this profile or the profile itself is changed, you need to type . $profile in package manager console to refresh the profile. Restarting VS also refreshes the profile.

Step 4: Copy over build-and-deploy-configuration.json to the webroot of your Visual Studio sitecore project.


I chose to include it in the project in a easy to access configuration folder in top of the helix structure.


Step 5: Add your unique parameters to build-and-deploy-configuration.json


Use package manager console in visual studio. Make sure you are running visual studio as administrator. Type the following commands in PMC:

build-and-deploy unicorn

Notes during development:

(A) Hangup on killing IIS worker process:

Usually solved by restarting computer. Probably also with a IIS hardreset. Can happen after a fresh sitecore 9 install with SIF.

(B) 32 bit powershell version:

The powershell that is used by package manager console is a 32-bit version. This limit us in using code that is only supported in the 32-bits version.

This limited the use of WebAdministration Module to manage IIS instance. What i ended up doing instead was to find the IIS worker process and kill it before running MSBuild.

(C) Permanent locked /roslyn/ dll due to used by another process:

Make sure you have the correct nuget packages installed (se prereq). Delete the old ones if you upgraded.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s