This week I’ve been working with a client to make changes to an existing CRM solution. The solution made use of a CRM WebResources solution in Visual Studio.  This project is maintained by a developer that has Visual Studio 2012 (VS2012) on his machine.  However, the computer I was using only had Visual Studio 2010 (VS2010).  As anyone that has upgraded an existing CRM solution project from VS2010 to VS2012 will know, the path to the build targets between the two versions is different.

Normally, the recommendation is to open the project file in a text editor, update the import targets path and away you go.  However, that is based on the principle that all people opening the project will be using the same version of Visual Studio.  What if you want to retain backward compatibility with VS2010?  VS2012 can work with VS2010 project files whilst still allowing them to be opened in VS2010.  The key to opening a CRM solution project in both versions of Visual Studio is make sure that the import targets path is correct for whichever version of Visual Studio it is opened in.

To achieve this, I went back to the MSBuild documentation for the Import element.  This element contains two attributes: Project, which is the path to the build targets; and Condition, which determines whether the given target is imported or not.  Normally, the condition for the CRM build targets is not specified.  However, this is what we can use to decide which targets to import.  The conditional can check the $(VisualStudioVersion) property to determine if the project is opened in VS2010 or VS2012.

The following is what I came up with and can be used to replace the existing CRM build targets import: