Sitecore: ZeroDeploy Tool

Introduction

ZeroDeploy Developer is a tool designed to improve the Sitecore development process by reducing the number of times the Sitecore development environment restarts. Normally, everytime you push new compiled code to Sitecore, the IIS Application Domain reloads itself. This process can take a while even on a fast computer and a clean environment. ZeroDeploy Developer prevents Sitecore from restarting every time compiled code changes.

This blog helps the developer setup ZeroDeploy in their local environment and shows some strategies that will help to get the most out of ZeroDeploy.

ZeroDeploy tool is being developed by Hedgehog, and at present it is in Beta 2 version.

Requirements

ZeroDeploy is designed to work on Sitecore 8.2 and later. The Visual Studio component of ZeroDeploy can only be installed on Visual Studio 2015 and 2017.

Getting Started:

Step 1:

  • Click on https://www.teamdevelopmentforsitecore.com/Zero-Deploy-Beta link, sign in with your company credentials (personal email id’s are not allowed). You can download ZeroDeploy zip folder and you will also receive an email from Hedgehog, which has the trial key.
  • Unzip the folder and double click on Hedgehog.ZeroDeploy.VSAddin.vsix to install it on VS 2015 and above.

Step 2: nuget setup

  • Copy all .nupkg files from the ZeroDeploy zip file to a local location (eg. C:\Projects\ZeroDeployBeta\)
  • Create a nuget.config to the root of your solution (next to your .sln file)
  • Update the nuget.config file with the following code. In line number 4, the path should be the location of your
  • ZeroDeployBeta nuget packages:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <packageSources>
    <add key="Zero Deploy Beta" value="C:\Projects\ZeroDeployBeta" />
    </packageSources>
    <activePackageSource>
    <add key="All" value="(Aggregate source)" />
    </activePackageSource>
    </configuration>
  • Open the solution. Right click on the main website project, usually located inside the Common folder and then select “Manage NuGet Packages…”

  • Change to the “Zero Deploy Beta” package source in the top right dropdown control, and switch to the Browse tab in the top left:
  • Select the Hedgehog.ZeroDeploy.Build package and install it.
  • Right click on the .Website project located inside the Common folder, you should be able to see Zero Deploy tab, as shown below:

Step 3: Sitecore Changes

ASP.Net has a feature to recycle the application pool automatically if it re-compiles too many views. This prevents memory leaks in a production environment due to obsolete view assemblies being held in memory. This is less of an issue in local development, and since ZeroDeploy allows you to make many changes to your assemblies without a recycle, this behavior is not desirable.
Setting the attribute numRecompilesBeforeAppRestart on the system.web/compilation element to a large number prevents .Net from recycling after a few View updates.

  • Update Sitecore’s web.config as shown:

    1
    2
    3
    4
    5
    <compilation defaultLanguage="c#" debug="false" targetFramework="4.5.2" numRecompilesBeforeAppRestart="200">
    <assemblies>
    ....
    </assemblies>
    </compilation>
  • Add ZeroDeploy components to your Sitecore instance:
    Go to /sitecore/admin/UpdateInstallationWizard.aspx, select the Hedgehon.ZeroDeploy1.0.0.12.update file (which is in ZeroDeploy zip folder), and install it.

Step 4: Changes to the Solution for the main project :

  • Create a new solution configuration: Click on Build->Configuration Manager
  • In Active Solution Configuration, select New
  • Create a new configuration as shown below
  • In the configuration drop down, select the Zerodeploy
  • Create a Conditional Compilation Symbol called ZERO_DEPLOY in Web Application project properties
  • Select the Zero Deploy property tab and fill the fields with respect to your project

    Click on View License add your trial key.
  • Update Properties/ApplicationInfo.cs as shown below

    1
    2
    3
    4
    5
    6
    7
    [assembly: AssemblyFileVersion("1.0.0.0")]
    #if ZERO_DEPLOY
    [assembly: AssemblyVersion("1.0.*")]
    [assembly: Hedgehog.ZeroDeploy.Client.Attributes.ZeroDeployAssembly]
    #else
    [assembly: AssemblyVersion("1.0.0.0")]
    #endif
  • Build the project once.

  • In your Sitecore instance, you should get your .Website assembly under ZeroDeploy item, as shown below:
  • Delete the ZeroDeploy assemblies from /bin folder of the main website project as shown:

Step 5: Changes to the Solution for Adding additional assemblies to ZeroDeploy

  • Add the Hedgehog.ZeroDeploy.Client NuGet package to the project you want to add ZeroDeploy support.
  • Make the changes to the Properties/ApplicationInfo.cs file:
    [assembly: AssemblyFileVersion(“1.0.0.0”)]

    1
    2
    3
    4
    5
    6
    #if ZERO_DEPLOY
    [assembly: AssemblyVersion("1.0.*")]
    [assembly: Hedgehog.ZeroDeploy.Client.Attributes.ZeroDeployAssembly]
    #else
    [assembly: AssemblyVersion("1.0.0.0")]
    #endif
  • Build the project. ZeroDeploy build process will push the assembly to your Sitecore instance. You should get a similar message in the output window:

  • Test your Sitecore instance. You should get the assembly in your sitecore, under Zero deploy tab, as shown
  • Delete the ZeroDeploy assemblies from /bin folder of the project as shown:

Usage

Work on your solution as usually. Every time you need to test a change that was made to a project, just build the project; the build process will copy the updated assembly to Sitecore and will automatically load it.Then you can test your changes in Sitecore.
From some quick tests we made: it takes about 3 minutes to get Sitecore up after a change in an assembly, after doing the same change with ZeroDeploy enabled, Sitecore is up in 10 seconds.

Known Limitations

  • Currently ZeroDeploy has no integrations made with TDS, that means that TDS projects have to be removed from the Build options when using ZeroDeploy configuration:

    But this also means the changes made to Views or configuration files will not be moved to Sitecore during a build. Hedgehog’s solution to this problem is to use gulp to automatically move these files when they have been modified.
    Additionally, please know that updating a configuration file will also cause the AppPool to restart, breaking ZeroDeploy functionality.

Initially blogged at http://deployzero.blogspot.in/2017/08/introduction-zerodeploy-developer-is.html

References:

Happy Learning :)

Share