Wednesday, 15 October 2014

Managing Microsoft Dynamics CRM Solutions in Source Control and Visual Studio

Background

We now manage our development world using agile.  And as such we link work items to specific user stories and features.  In our development team we are doing this via TFS.  When ever we check source code in we find the relevant work item, which is parented by a user story and feature alike.  

This is fine if you are writing code in a native Visual Studio code-base, but not fine if you are wanting to link changes made to your dynamics CRM to specific work items.  

Intended Solution

My idea was to export or unpack a specific set of changes to CRM via the unmanaged solutions save them unpacked as XML to a location where my source control could pick them up and then apply them.  Once in source control I could then associate changes to work items for CRM customization.

Once in source control I could then re-pack the solution into a deploy-able zip so that I can then apply this to me staging environment.  

So in summary the steps are:
  1. Get a list of solutions for a particular CRM instance from Visual Studio
  2. Export the solution 
  3. Unpack the solution to a location visible to source control
  4. Check in changes for solution
  5. Continuous integration server would then pick up any changes from the solution and re-pack them into deploy-able zip
  6. deploy to staging environment

Create a Visual Studio Extension that lists solutions for an instance of CRM

Using the Visual Studio SDK and the CRM SDK  I have created a Visual Studio Extension.

As you can see it populates a list of solutions in CRM based upon the Organization name:
CRM Solutions Manager
The user selects a solution from the list and then clicks download.  This used the CRM SDK and webservice to pull down the ZIP as a stream of bytes and then unpacks to a given location.

The location and CRM webservice call details are stored in a series of options built into the Visual Studio Extension.  As per below

CRM Solutions Manager Options
Once the download is complete it will download to the given source path where your source control software (Ours is TFS) can pick it up, at that point you can add the unpacked XML can be added to source control. As seen below.



As if by magic you now have CRM Solutions unpacked managed within visual studio and in source control.  The next step is to link this to your CI or build process.

Re-pack the solution from check in and Build Deploy-able solution zip

Once the files are checked into source control, we would have CI (Continuous Integration) or build server in place to pick up those changes and download them.

Our CI server has Cruise Control.NET installed and also Microsoft Dynamics CRM SDK.

As part of your build process you then run a command that packs the solution ready for deployment to your staging or UAT environment.

The command is as follows:

C:\CRM_SDK\SDK\Bin\SolutionPackager.exe /action Pack /zipfile <YourLocation>.zip /folder <YourLocationFolder>
If you like the visual Studio Extension related to this post please comment and I will look at providing it.