Creating deployment packages for CRM 2013

The spring 14 update of the CRM 2013 SDK (Leo) comes with a number of new tools, including a new deployment framework. The short version is that it allows you to build a deployment package in Visual Studio (with customizations, data and custom code steps) and deploy the package to CRM with a visual tool or even better: With PowerShell.

This post is about creating the deployment packages with Visual Studio. I will write a post on how to deploy the package later on.

What can it do?

With the new Visual Studio template, you can create packages that will let you:

  • Deploy CRM Solutions
  • Deploy data packages created with Configuration Manager
  • Deploy data in CSV or XML file formats with CRM Map files
  • Execute custom code (.net) during deployment process
  • Display information to the user before and after the deployment process in HTML format

Getting started

Before you start building your deployment package, you need to install a new Visual Studio template.

Download the SDK and run \SDK\Templates\CRMSDKTemplates.vsix

Now you are ready to start Visual Studio. Do so and create a new project of type CRM SDK Templates\CRM Package.

4

The project structure

The project tree includes a number of interesting elements that we need to know how to use. I have “highlighted” the most interesting below:

2

The PkgFolder is where you place you content: CRM solution files, Configuration Manager zip files and xml/csv files.

The two default.htm files are where you can edit the message shown to the user before and after deployment.

ImportConfig.xml is where you configure what should happen during deployment (what solutions to import, what data files etc)

The PackageTemplate.cs is where you can hook up you own custom code.

PkgFolder

When you want to add content to this folder you should copy you files to its root. Not to the Content folder, but directly in the PkgFolder. After adding files (say a CRM solution file) you need to right click it, choose Properties and then set Copy to Output Directory to Copy Always.

3

The files you add to you PkgFolder also need to be added to the ImportConfig.xml file (see below). Be aware that while you can add as many Configuration Manager zip files to the folder as you wish, you can only configure one for import in the ImportConfig.xml file.

Default.htm

These files can be edited with whatever information you like to you user. If you import you package with PowerShell it looks like they are ignored all together.

ImportConfig.xml

Edit this file to specify the steps of the deployment procedure. Fresh from start the file looks like this:

<?xmlversion="1.0"encoding="utf-16"?>

<configdatastoragexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"

installsampledata="false"

waitforsampledatatoinstall="true"

agentdesktopzipfile=""

agentdesktopexename=""

crmmigdataimportfile="">

<solutions>

<configsolutionfilesolutionpackagefilename="solutionFile.zip" />

</solutions>

<filestoimport>

<configimportfilefilename="File.csv"filetype="CSV"associatedmap=""importtoentity="FileEntity"datadelimiter=""fielddelimiter="comma"enableduplicatedetection="true"isfirstrowheader="true"isrecordownerateam="false"owneruser=""waitforimporttocomplete="true"/>

<configimportfilefilename="File.zip"filetype="ZIP"associatedmap="ZipFileMap"importtoentity="FileEntity"datadelimiter=""fielddelimiter="comma"enableduplicatedetection="true"isfirstrowheader="true"isrecordownerateam="false"owneruser=""waitforimporttocomplete="true"/>

<zipimportdetails>

<zipimportdetailfilename="subfile1.csv"filetype="csv"importtoentity="account" />

<zipimportdetailfilename="subfile2.txt"filetype="csv"importtoentity="contact" />

</zipimportdetails>

</filestoimport>

<filesmapstoimport>

<configimportmapfilefilename="FileMap.xml" />

<configimportmapfilefilename="ZipFileMap.xml" />

</filesmapstoimport>

</configdatastorage>

But after I edited it to fit my simple needs (a CRM solution, some data from Config manager and a little custom code) it looked remarkably simpler:

<?xmlversion="1.0"encoding="utf-16"?>

<configdatastoragexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"

installsampledata="false"

waitforsampledatatoinstall="true"

agentdesktopzipfile=""

agentdesktopexename=""

crmmigdataimportfile="data.zip">

<solutions>

<configsolutionfilesolutionpackagefilename="MyFavoriteSolution_1_0_0_0.zip" />

</solutions>

</configdatastorage>

The key elements are crmmigdataimportfile attribute where you specify the Configuration Manager zip file (data) to import and the <solutions> element where you specify the CRM solution files to import.

All the FilesToImport stuff is related to importing csv or xml files during import. I haven’t really tried yet, but I might post an update about that once.

PackageTemplate.cs

This is where you can write you own cod that gets executed during the deployment process at various stages.

As far as I can tell you have three hooks:

  • BeforeImportStage
  • RunSolutionUpgradeMigrationStep
  • AfterPrimaryImport

So you can execute code before it all begins, when a solution is upgrated or after the import of solutions (and data? I’m not sure yet) is completed.

An example:

public override bool BeforeImportStage()
{
   CrmSvc.OrganizationServiceProxy.Create(newEntity("lead"));
   return true;
}

It might not be very useful, but the code will create an empty lead before importing solutions and data. The point is that you have a hook to the CRM OrganizationService, so you can do all you CRM manipulations. Remove a field that is no longer used for example.

Deploying the package

Once you have built you package you can deploy it to you CRM system. There are two options: A windows client or PowerShell.

My next blog post will be about deploying CRM Deployment Packages with PowerShell.

Conclusion

This looks promising. Obviously, we haven’t used this on real projects (the tools are less than a week old) but as far as I can tell this will be the default choice for deploying CRM solutions in the future. The ability to bundle together customizations and data, and to manipulate the system with code is awesome. +1 for the CRM SDK team at Microsoft :)

 

CRM Configuration Manager

The SDK for the Spring 14 release (Leo) of CRM 2013 comes with a few new tools. One of them is called the Configuration Manager. The executable file is called DataMigrationUtility.exe and that name nails it. It’s a tool for moving data from one CRM system to another.

So far, I am impressed, the tool works great and from my point of view, it will become an essential part of many of our projects. Not so much for migrating data from one production system to another, but more for deploying base data (zip codes, countries, etc…) to production and test systems, and test data to test systems. It’s a great tool for building a set of data packages with a shared set of test data (placed in source control of course) that can easily be deployed to new instances of test systems, or used to “reset” your test environments.

The tool integrates very well with the new CRM Package Deployer and the new Visual Studio template for building deployment packages for CRM.

Great work Microsoft!

Getting started

To start the program run \SDK\Tools\ConfigurationMigration\DataMigrationUtility.exe

1

You now have three options: Create schema, Export data or import data. Basically a schema is a definition of what data to export and how to import it.

To get started chose to create a new schema and click Continue. Next window is the new common login window that the SDK team is applying to all its tools. We used to have a different flavour for each tool, now there is one. And it is easy to use!

2

 

Enter your credentials for you CRM 2013 server and click login.

Now you are ready to design you Schema, by defining what files from what entities should be exported/imported. Don’t click “Add all” on your default solution – that literally means exporting your entire CRM system. Choose the entities you want to add and click add entity.

3

Notice how it includes relationships. The tool maintains relationships across systems for you, and you don’t even have to configure it.

There are a few options for the import process that can be defined in the schema. If you click Tools – > Configure import settings you can, among other things, disable plugins during import for single entities or the entire system. Useful in some cases.

Once you are done you can save your schema from the File menu or you can click Save and Export. The later will both save the schema and export the data as configured.

4

Import

This is really simple: Click import (from the start screen of the application), choose a zip file to import (notice how the schema is saved in the zip file along with the data) and click Import data.

5

Export (in case you have your schma defined up front)

Click Export Data from the start screen. Choose a schema file (the one you defined with the schema designer) and a zip file that you want to export your data to. Click Export data and wait for the process to complete.

6

 

There is much testing to be done before I can give my final review of the program. Does it handle statecodes, closed activities, owners, business units etc.? I don’t really know yet. But from what I have seen so far, the tool is great and the fact that the output (zip files with schema and data) can be used as part of the deployment process with the new CRM Package Deployer is a killer feature.