Analyzing code changes in the Sitecore Kernel

17 maart 2014 om 00:00 by Ruud van Falier - Post a comment

When Sitecore releases a new version, I always want to know exactly what has been changed.
Of course, they inform you about this using the Release Notes, but I'm a developer and I prefer reading code over just words in a story!
More importantly, upgrading can some times lead to unexpected behaviour in your existing solution and in scenarios like that, what you really want to know is what exact changes Sitecore has made to their code.

This article explains how to figure out exactly what code has been changed in between two versions of Sitecore.
I find that it can be very useful in some cases and potentially save you a lot of time.


First of all, you'll need to install some tools.
(but you being a Sitecore enthusiast, will already have them installed, of course!)

  1. Install dotPeek.
    This is a free .NET decompiler that allows you to look at the source code of .NET assemblies.
    If you prefer to use Reflector, that works fine as well, it's just not free.
  2. Install Notepad++.
    This is an awesome free text editor.
  3. Install WinMerge.
    This is an open source tool for comparing and merging files.

Example scenario

As an example, we're going to find out what has changed between Sitecore version 7.1 (Initial Release) and 7.2 (Initial Release).

Step 1: Decompile the kernels

First of all, we'll need to decompile the Sitecore.Kernel.dll from both Sitecore versions and store all the source files on disk.

  1. Open dotPeek.
  2. Load the Sitecore.Kernel.dll file from Sitecore 7.1
  3. Right-click the assembly in the Assembly Explorer and choose Export to Project.
  4. Export the assembly to <some-folder>\Kernel-Export\v71\.
  5. Unload all assemblies (in the Assembly Explorer, Select all -> Right-click > Choose Remove Item from List).
  6. Load the Sitecore.Kernel.dll file from Sitecore 7.2
  7. Right-click the assembly in the Assembly Explorer and choose Export to Project.
  8. Export the assembly to <some-folder>\Kernel-Export\v72\.

Step 2: Remove useless data from the files

So now we have the source code for both kernel versions on disk.
The idea is that we're going to compare those files with WinMerge to find differences between them.
However, each source file contains a unique header, so they will all be different.
This is where Notepad++ comes into play.

// Type: Sitecore.Access.AccessContext
// Assembly: Sitecore.Kernel, Version=, Culture=neutral, PublicKeyToken=null
// MVID: 5C2DE085-F6F4-482F-847D-A78B29CE7A7B
// Assembly location: C:\data\projects\sitecore-v71\Website\bin\Sitecore.Kernel.dll

The above is an example of the header that is added to every source file by dotPeek.
To remove these file headers, follow these steps:

  1. Open Notepad++
  2. Go to Search -> Find in Files...
  3. Set Find what to: //.*\r\n//.*\r\n//.*\r\n//.*\r\n
    That will match all the file headers that are generated by dotPeek.
  4. Leave Replace with empty.
  5. Set Filters to *.cs
  6. Select your export directory (<some-folder>\Kernel-Export\).
  7. Set Search mode to Regular expressions.
  8. Enable In all sub-folders.
  9. Click Replace in Files.
  10. Wait for the replace to finish (this may take a few minutes...)
  11. Repeat from the start, but this time set Find what to: \[.*\]\r\n
    That will match all code attributes. If you skip this step, you will get a lot of differences in the comparison just because the order of attributes has changed.

We are now ready to start the comparison!

Step 3: Compare with WinMerge

So now that we have the before and after state of the kernel source file, we can use WinMerge to put them next to each other and make a comparison.

  1. Open WinMerge.
  2. Go to File -> Open.
  3. Set Left to the export folder for version 7.1
  4. Set Right to the export folder for version 7.2
  5. Set filter to *.cs
  6. Enable Include Subfolders.
  7. Click OK.
  8. When the comparison has finished, order the results by Comparison result to see the changed files first.

WinMerge will give you a nice list of all the files that have been changed.
Double-click on a file to see the differences between the two versions.

Using a decompiler to look at Sitecore's kernel source code is a very powerful tool by itself.
Knowing how to compare that source code with older versions will give you even more insight into the way Sitecore works.