Building CRM Solutions with TFS Build

Using the xRM CI Framework and TFS Build you can easily automate the build of your CRM Solutions.

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.

  1. Compile your Visual Studio Solution (Plug-ins, Custom Workflows, Silverlight, Dependencies, etc…)
  2. Run Unit Tests
  3. Invoke CRM Developer Toolkit CrmPackage project deployment (deploy solution components from source control)
  4. Publish Customizations
  5. Update CRM Solution version number from TFS Build number (the part after the ‘_’)
  6. Export your CRM Solution from a CRM Instance
  7. Unpack an exported CRM Solution using Solution Packager and update your source control
  8. Update version number of your unpacked solution stored in source control (“\Other\Solution.xml”)
  9. Pack your customizations from source control and produce a CRM Solution Package
  10. Invoke a PowerShell script to further extend the Build and/or deploy your solution and dependencies
  11. 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.

Dynamics CRM 2011 TFS Build Template Flow

Dynamics CRM 2011 TFS Build Template 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.

In the meantime you can have a go at creating a build definition using the template after following the setup instructions in my previous post.


Posted on August 15, 2013, in CRM 2011, Dynamics CRM, xRM CI Framework and tagged , , , , , , , , , . Bookmark the permalink. 19 Comments.

  1. Getting errors : Faild to load the following parameters : Export Type & Pack Type



  2. This is great content. I have been working through getting this to wrok with a simple solution. However, the Deploy step for my plugins is failing saying “C:\a\src\XRM CI Test\Packages\MSBuild\CRM\Microsoft.CrmDeveloperTools.12.targets (176): The “Microsoft.CrmDeveloperTools.CrmClient.MSBuild.RegisterPlugin” task could not be loaded from the assembly C:\a\src\XRM CI Test\Packages\MSBuild\CRM\Microsoft.CrmDeveloperTools.dll. Could not load file or assembly ‘Microsoft.Xrm.Sdk, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.”. The build target seems to have been registered properly and is in TFS (i can see that it pulled all the CRM Build target files from TFS in tehd etailed log). Any ideas on what I could be doing wrong here?

    • Hi Matt. I think you are using TFS 2012 online?

      Seems like you are missing the Microsoft.Xrm.Sdk.dll assembly in the folder containing the targets file.

      Also check my other post on building CRM on the hosted build controller.

  3. Wael,

    Thanks for the response. I see where the problem is. Your example showed putting the Build .target and other files into the same directory as the SDK DLL’s where I had it in a seperate directory. The Developer Toolkit doesn’t include all the files it needs under the build directory, so this resulted in the missing reference on the deploy step.

    Do you plan to detail out each of the various sections of the Build process and the parameters? Some of them are not as intuitive to setup and trial and error gets old real quick.

    • Matt,

      Glad you got the first part working.

      Yes I am planning to publish more posts as soon as I get more time. In the meantime if you have any questions, I am happy to provide quick answers.

  4. Word to the wise, DO NOT put spaces in your Solution path. I made the mistake of first generating my Developer Toolkit solution with the name “CRM CI Test” and the deployment step was failing saying it had issues serializing the registration file. Made a copy of the same solution w/o spaces in the name and it worked fine.

  5. Hi Wael,

    Very good job with the framework. I was wondering if it would work with a TFS2010 build agent and VS2012 installed on the build agent machine.
    I seem to have some issues when I am kicking off the build, it complains about a method it cannot find:


    A further investigation on MSDN revealed that this is a method that has been added in VS2013c so it does not exist for v10 and v11 of the Microsoft.TeamFoundation.VersionControl.Client assembly.

    Any ideas?

    • Hi Harry,

      The Framework references some of the assemblies from the TFS 2012 Build. I don’t think this will work with TFS 2010 build agents.

      Are you able to upgrade to TFS 2012 or do you require the TFS 2010 version of the Framework?

      • Hi Wael,

        We are looking to upgrade to TFS2012 but it might take some time. It would be great if you have a version to work with TFS2010.

  6. Hi waelhamze,

    Thanks for the template.

    I am currently having an issue while running the build with the following log error:-

    Microsoft.Crm.CrmException, Microsoft.Crm.Core, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    The user Id is invalid.

    I am thinking its down to the Crm Connection Details Parameter.

    Please can you give me the full string which you use as I can not see it in the image.

    Many thanks

  7. Hi Wael,
    My source code is getting compiled perfectly but the build process fails after that and the following exception is thrown:

    Exception Message: Value cannot be null.
    Parameter name: Input (type ArgumentNullException)
    Exception Stack Trace: at Microsoft.TeamFoundation.Common.TFCommonUtil.CheckStringForNullOrEmpty(String stringVar, String stringVarName, Boolean trim)
    at Microsoft.TeamFoundation.Build.Workflow.Activities.ConvertWorkspaceItem.Execute(CodeActivityContext context)
    at System.Activities.CodeActivity`1.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
    at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

    Can you provide any pointers as to what’s causing this to happen and how should I resolve it.

    • I am getting the same error, have some found a solution?

      • Hi Morten,

        Are you still getting this error? What operation are you trying to do? I don’t think you can add anything to the connection string. Have you tried installing a certificate on this machine to trust the other certificate? I don’t think the code at the moment by passes certificate validation.

  8. Hi Wael,

    I have followed the instructions in your page on how to use the framework(Install,etc) and it was successful in the expected environment (CRM 2013,TFS2013, VS2013). But since our Setup is in (CRM2013,TFS2012, VS2012) using the DynamicsCrm2013Template didn’t work in VS2012 and i tried DynamicsCrm2011Template instead. and here’s what the error indicates, note: error will not prompt if i dont use features of CRM in the template

    Exception Message: Could not load file or assembly ‘Microsoft.IdentityModel, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified. (type FileNotFoundException)
    Exception Stack Trace: at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.CreateLocalChannelFactory()
    at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.CreateChannelFactory(ClientCredentials clientCredentials)
    at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration.CreateChannelFactory(ClientCredentials clientCredentials)
    at Microsoft.Xrm.Sdk.Client.ServiceProxy`1.get_ChannelFactory()
    at Microsoft.Xrm.Sdk.Client.ServiceProxy`1.CreateNewServiceChannel()
    at Microsoft.Xrm.Sdk.Client.ServiceContextInitializer`1.Initialize(ServiceProxy`1 proxy)
    at Microsoft.Xrm.Sdk.Client.OrganizationServiceContextInitializer..ctor(OrganizationServiceProxy proxy)
    at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request)
    at Microsoft.Xrm.Client.Services.OrganizationService.InnerOrganizationService.UsingServiceTResult
    at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request)
    at Microsoft.Xrm.Sdk.Linq.QueryProvider.RetrieveEntityCollection(OrganizationRequest request, NavigationSource source)
    at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute(QueryExpression qe, Boolean throwIfSequenceIsEmpty, Boolean throwIfSequenceNotSingle, Projection projection, NavigationSource source, List`1 linkLookups, String& pagingCookie, Boolean& moreRecords)
    at Microsoft.Xrm.Sdk.Linq.QueryProvider.ExecuteTElement
    at Microsoft.Xrm.Sdk.Linq.QueryProvider.ExecuteTElement
    at Microsoft.Xrm.Sdk.Linq.QueryProvider.System.Linq.IQueryProvider.ExecuteTResult
    at System.Linq.Queryable.FirstOrDefaultTSource
    at Xrm.Framework.CI.Common.ExportSolution.Export(Boolean managed, String outputFolder, String solutionName, Boolean exportAutoNumberingSettings, Boolean exportCalendarSettings, Boolean exportCustomizationSettings, Boolean exportEmailTrackingSettings, Boolean exportGeneralSettings, Boolean exportIsvConfig, Boolean exportMarketingSettings, Boolean exportOutlookSynchronizationSettings, Boolean exportRelationshipRoles)
    at Xrm.Framework.CI.TeamFoundation.Activities.ExportSolution.Execute(CodeActivityContext context)
    at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
    at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

    Is it possible to use the framework in our setup?
    need help. thanks.

  1. Pingback: Automate your Dynamics CRM Builds and Deployments with PowerShell | Wael Hamze

  2. Pingback: How to create an Automated TFS Build for Dynamics CRM Solutions? | Wael Hamze

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: