Microsoft

Keeping Your Sitecore References Consistent Among Your Developers

As a best practice, I do my project work outside of my Sitecore directory. I also as a best practice, segregate my Sitecore assemblies for my project compilation by copying them to a folder included in the solution.
There are some times that I don’t always get to follow my preferred best practices. On more than one occasion I have been involved with projects in which the team prefers to compile against the assemblies within the local developer’s Sitecore instance. When this happens I also tend to see a development team struggle with maintaining the consistency of their environments. When a developer installs their Sitecore instance in a completely different relative location to the project, usually we see broken references until everyone gets on the same page.
To make it a bit easier, here is something your teams can do to allow your developers to have their Sitecore instance installed where they please and keep your project references fluid.
In this example we will start out with a simple solution:
Solution_1
Within your solution add a new XML file into the solution:
Solution_2
Within the XML create the following:

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <PropertyGroup>
    <SitecoreReferencePath>C:\bin</SitecoreReferencePath>
  </PropertyGroup>
</Project>

The SitecoreReferencePath inner value should contain the developer’s local path of their Sitecore referenced assemblies.
Make sure that this new file is included within source control. However you want your developers to modify it locally but not be able to commit their changes. This file will be unique to each developer in their local environment.
Let’s change the project files in the solution to use the new path. Unload the project from the solution and edit the project file.
Add the initial line to your project file:
<Import Project="..\SitecoreReferencePath.xml" Condition="Exists('..\SitecoreReferencePath.xml')" />
Solution_3
Now to change the reference paths in the ItemGroup section. In the HintPath, add $(SitecoreReferencePath) in front of the assembly name.

<Reference Include="Sitecore.Kernel">
      <HintPath>$(SitecoreReferencePath)\Sitecore.Kernel.dll</HintPath>
</Reference>


Solution_4
In providing this MSBuild property for use for all projects in the solution, we can no longer cares about having the same consistent location in each development environment. The developers can install their Sitecore instance where they please without conflicts among the other developers on the team whom want their Sitecore instance in a different file path.
This can be done with any project with external dependencies for compilation and not just for Sitecore projects.

About the Author

Mark Servais is a software solutions professional with experience in creating solutions using Sitecore and the Microsoft stack of technologies. Experienced in project and development lifecycles through several viewpoints that include project management, development, and leadership. Mark has over 25 years’ experience in software engineering and application development. Mark has been awarded Sitecore’s Technology MVP award from 2014-2017 and currently holds a Master’s degree in Software Engineering from Carroll University.

More from this Author

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up
Categories