In this post I will show you how to fully automate the build of your Dynamics CRM Solutions using TFS and the xRM CI Framework. Creating an automated build when you start a new project is probably the least things on your mind when you have so many requirements to worry about. For this reason I tried to make this process easy and intuitive so you can get this up and running with a few clicks. This will definitely save you time down the line and make your overall process more consistent and reliable.
For this post I am going to show you how to do a Dynamics CRM Online Automated Build. I do not mean the cloud version of Dynamics CRM in this case. I mean creating CRM Solutions by exporting them from an available CRM environment. In this scenario the development team have decided that they want to use Dynamics CRM as their golden source of customizations as opposed to source control. I will assume that you are using the CRM Developer Toolkit to develop your custom assemblies and web resources.
Before you proceed. Follow the instructions in my previous posts to learn more about the xRM CI Framework for CRM 2011 & 2013. Also make sure you have completed the setup instructions detailed in this post.
The first thing is to create a TFS Build Definition. This provides all the configurations values that define what takes place once your build is triggered. The main difference is that instead of using the default build template we are using the customised build template that comes with the xRM CI Toolkit. This will give you the additional options that will allow to build your CRM solution as I will describe below. The default parameters are still available. These form the basis of all builds. If you need more information around these I suggest you read this msdn article. Below is a screen shot of the customised template so you can see what I mean.
Check my previous post to learn about the flow of this build. Below are step by step instructions to create your first Dynamics CRM Build definition.
- Enter your build name. This should take into consideration the CRM Solution name, the source control branch, the build type and any other criteria you want to include.
- Select the trigger. I suggest you start with a Manual trigger until your build is working as expected, you can then change it to run on check-in or scheduled basis.
- Select the source. This would be the folder containing the visual studio solution that contains the projects for your plug-ins etc…Ideally this should have been created using the CRM Developer Toolkit. But this is not a requirement.
- Set the build controller. TFS online comes with a default build controller. For on premise version you will need to have this setup. Make sure you have configured the build controller with the custom toolkit assemblies as detailed in the installation guide. Also set the Drop Folder. This is where all the outputs will be placed including the exported CRM solutions.
- Process. This is where the build workflow is configured. Select the Dynamics CRM Build template from the toolkit as per the installation guide.
- Set the items to build and configurations. In this case this is your visual studio solution contains all the things you want to build. If you only have customizations in CRM, you can skip this step.
- Configure your test settings if you want any unit tests to run as part of your build. Then set the build number format. Use a format similar to the below if you are planning to use this number for your CRM Solution versioning as well. You can update this later if needed to increment your major or minor versions.
- Set the CRM connection string. The format follow the CRM Sdk connection string. Note if you click on the dots in the field you will be able to provide this using a wizard. Don’t worry you can still update the field manually later to add things such as timeout settings. Then provide the unique solution name. These settings will be used in the following sections for connecting to the Dynamics CRM Server.
- Complete this section if you are using the CRM Developer toolkit and you want to perform the equivalent of deploy from visual studio to ensure that the target CRM environment is inline with your source code before doing the export. The parameters are self explanatory except for the table below.
Parameter Name Description Check-In Register File When you perform a deploy on the CrmPackage project using the CRM Developer Toolkit this updates the RegisterFile.crmregister file with the assembly and step GUIDs from CRM. Set this to true to check-in these changes post deployment or false to discard. Copy Dependent Packages If you add any dependent CRM Solutions to your package project, setting this to true will copy all of these solutions to the drop folder. Enable Deploy If this is set to False then this section will be skipped and no deployment will take place.
- Final and most important step. This export the CRM Solution from the specified environment into the drop location. You can optionally publish customizations and increment the Solution version number inline with the build number.
Parameter Name Description Enable Solution Export Setting this to False will inform the build to skip this section completely Publishes Customizations Publishes all the customizations prior to the export operation Update Solution Version to Build Setting this to True will inform the build to update the version number of the CRM Solution in the specified CRM Environment to the Build version number (the part after the ‘_’). This happens before the export operation.
- Save the build definition. Trigger a new build and wait until this complete. If everything went ok you should see something similar to the below. Notice that I also get my unit test results and the code coverage.
- Finally go to the drop location for that build. You should see all the outputs including the exported CRM Solutions. Notice in this case my solutions have the same version as the build number.
By now you should have a fully automated build. That you can re-use. Off course not all builds are simple as this. But this will cater for many scenarios.
Watch out for the up coming posts. I will show you how you can use the CRM Solution packager to do your builds and implement Continuous Integration including extending your builds to deal with more complex scenarios.
The xRM CI Framework is a set of tools that allows you to quickly and easily implement Continuous Integration for your Dynamics CRM solutions. This includes fully Automated Builds & Deployments.
Dynamics CRM 2013 has been recently released and come with lots of new exiting features and capabilities. These include an updated SDK. To compliment this release I have updated the xRM CI Toolkit to take advantage of these new capabilities. Hopefully this will allow you to put in these best practices and automation in place as you start your new Dynamics CRM 2013 projects.
Below is a list of updates from the CRM 2011 version:
- Support for Dynamics CRM 2013 Online/OnPremise
- Uses the latest Dynamics CRM 2013 SDK
- Compatibility with the new CRM Developer Toolkit for Dynamics CRM 2013
- Asynchronous Solution Imports (Check my other post here)
- Sample PowerShell Scripts
Check my previous post for a list of the CRM 2011 version features that are still supported in this release.
Watch out for more posts regarding the above new features and new releases. This will include compatibility and new features for Visual Studio and Team Foundation Server 2013.
Note that even this release you can use the existing automated build templates with TFS 2013. However at this point in time the CRM Developer Toolkit does not work with Visual Studio 2013.
Finally you can download the new Framework from the Visual Studio Gallery here.
In this post will go through the details of the Dynamics CRM TFS Build template “DynamicsCrm2011Template.11.1.xaml” that makes of all this possible. Before I proceed further, a TFS Build template is a workflow that defines the flow and steps of a TFS Build. This is normally implemented using Windows Workflow Foundation. TFS Build allows you provide custom build templates to suite your needs.
The Dynamics CRM 2011 TFS build template extends the default TFS Build template to provide the extra steps required to Build CRM Solutions and implement Continuous Integration.
Below are the high level steps the Dynamics CRM Build will go through. Note that all these steps can be configured using parameters and can be turned on or off to suite your specific scenarios.
- Compile your Visual Studio Solution (Plug-ins, Custom Workflows, Silverlight, Dependencies, etc…)
- Run Unit Tests
- Invoke CRM Developer Toolkit CrmPackage project deployment (deploy solution components from source control)
- Publish Customizations
- Update CRM Solution version number from TFS Build number (the part after the ‘_’)
- Export your CRM Solution from a CRM Instance
- Unpack an exported CRM Solution using Solution Packager and update your source control
- Update version number of your unpacked solution stored in source control (“\Other\Solution.xml”)
- Pack your customizations from source control and produce a CRM Solution Package
- Invoke a PowerShell script to further extend the Build and/or deploy your solution and dependencies
- Run Integration tests on your selected environment
Using various combinations of the above you can implement different types of builds to suite your needs.
Note that all components required to build your CRM Solution should be either in source control or CRM instance for the Build Template to work correctly.
As I mentioned before all of the above can be configured very easily using the TFS Build user interface inside visual studio. So you can create a new build definition in a matter of minutes.
To visualize the build workflow for Dynamics CRM, below is a Visio diagram showing the main flow.
In the coming posts I will go into the details of the different types of Builds you can create and how you can use this template to implement these.
The xRM CI Framework is a set of tools that allows you to quickly and easily implement Continuous Integration for your Dynamics CRM solutions.
The framework provides an implementation of some of the concepts detailed in the recently published Microsoft Dynamics CRM Application Lifecycle Management (ALM) white paper. The framework is also compatible with the Dynamics CRM Developer toolkit from the SDK.
The framework allows you to improve efficiency and consistency by automating your build and deployments using Team Foundation Server (TFS) 2012 and PowerShell.
Below is the list of features provided in the first release.
- Dynamics CRM TFS Build Template that allows you to easily create your Check-In, Continuous Integration, Nightly and Release Builds
- Dynamics CRM PowerShell Cmdlets to extend your build process and automate your deployments
- Ability to support online & offline Dynamics CRM Builds (Build from CRM instance v.s. from source control)
- Ability to trigger automated deployments from your TFS Builds
- Ability to run Integration Tests from your TFS Builds after deployment
- Automatic versioning of your CRM Solutions inline with your TFS Build number
- Ability to automate the updating of your customisations stored in source control from CRM using the solution packager
- Support for Dynamics CRM on-premise & online
- Support for TFS 2012 on-premise & online
- Easy to use and extensible to meet your specific scenarios
Apart from the benefits above you will also get all the benefits of using Team Foundation Server Build to improve your ALM.
There will be a series of blog articles to show you how you can use the framework to implement your specific scenarios in your projects.
In the meantime you can download a copy of the framework from the visual studio gallery.
Don’t forget to check out the setup post on how to get started.
In this post I will provide you with the details on how to setup the xRM CI Framework.
The process is simple and easy. After this stage you will be ready to create your automated builds and deployments.
Framework Download & Installation:
- The first step is to download the setup files from the visual studio gallery.
- Run the setup which will copy all the required files to the installation directory “C:\Program Files (x86)\Xrm CI Framework”.
Automated Build Template Setup:
- The first step is to copy the contents from the installation directory “C:\Program Files (x86)\Xrm CI Framework\CRM 2011\VS 2012\TFS Build Templates” and store them under source control in TFS.
- Once the files are under source control, you will need configure your Build Controller to use the custom assemblies required by the template.
- Follow this link to perform the two steps above. This is based on TFS online but you can use the same process for TFS on premise.
- The final step is to register the Dynamics CRM 2011 Build templates with TFS. Follow this link to register the template by selecting the template from the location in source control from the previous step.
- Now you should be ready to create your first Build Definition using the Dynamics CRM 2011 template.
Dynamics CRM PowerShell Cmdlets Setup
- Start the PowerShell Console and run the command below.
- Import-Module “C:\Program Files (x86)\Xrm CI Framework\CRM 2011\PowerShell Cmdlets\Xrm.Framework.CI.PowerShell.dll”. This will give you access to all the xRM CI Framework PowerShell Cmdlets.
If you are running this on Windows 7 or 8. You will most probably have PowerShell using .NET 2.0 and encounter some errors. To force PowerShell to use .NET follow this blog.
- Create your PowerShell Script using the Cmdlets
This article demonstrated how to setup the xRM CI Framework. In the next blogs i will show you how to configure different types of builds and deployment to suite your specific scenario.
If you have installed the new Dynamics CRM 2011 Developer Toolkit for Visual Studio 2012, you might notice that package projects created using the old developer toolkit fail to load. This is manifested in an error similar to the below.
To fix the problem follow the steps below:
- Right click on the package project and click Unload
- Right click on package project and click on Edit
- Replace “<Import Project=”$(MSBuildExtensionsPath32)Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.targets” />” with “<Import Project=”$(MSBuildExtensionsPath32)Microsoft\CRM\Microsoft.CrmDeveloperTools.12.targets” />”
- Right click on the package project and click on Reload
This will fix the problem. The problem is because the target files location is different between the developer tools for visual studio 2010 and visual studio 2012.
Hope this helps