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:
Within your solution add a new XML file into the solution:
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')" />
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>
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.