Deploying CRM with TFS 2015 tasks and PowerShell

Recently I was asked to put together some automation that would Deploy’s a  CRM solution with Solution Packager.  This Blog post is about how I did that.

I started with the documentation on Solution Packager.   What I found was that I could write a simple script that takes the source location for the Solution and packages it into a zip.  Here is what that run line looks like:

.\SolutionPackager.exe /action:Pack  `
/folder:'C:\CRM\CRM Solutions\default' /zipfile:c:\temp\  `

So now to put a try catch around it and some other House keeping.  Since I’m going to call this from TFS I need to make certain that I have a way to allow for -debug and the other standard switches with a Powershell script so I’ll include [CmdletBinding()]. The full script is below:

 $zipfile = 'Crm'
$ErrorActionPreference = 'Stop'
$sourcefolder = (Get-Item $SourceFolder).FullName
"ZipfFileName: $sourcefolder\$"
 & .\SolutionPackager.exe /action:Pack /folder:$SourceFolder `
"/zipfile:$sourcefolder\$" /packagetype:unmanaged 
 Write-Error $_.Exception.Message
 exit 1
 Get-ChildItem -Path "$sourcefolder\$" -Verbose

Now that I have the Solution zipped up from what the developer checks into source I need a means to deploy it.   The Powershell Developer in me wanted to write a script of my own, I found that someone had already written this capability and all I needed to do was to add it to TFS.    Here is what I found:

A Developer by the name of Chaminda Chandrasekara created a Plugin to TFS (task) that does a solution import and activation of workflows.

Now with that in mind I added Chaminda’s code to my release process in TFS and then added the script that I created to my build process in TFS for the full solution.   I did need to create a task for my script shown above.  This was done by following the steps found here.


My build process steps consist of two steps.

Step 1 is to create the package. 2016-11-03-09_31_18-microsoft-team-foundation-server

Step 2 is to copy the artifacts to a Staging directory


Now onto the release process which also consists of two steps.

Step 1 is to do the solution import:


In this setup I specify the name of the Zip file from the earlier build.  I have TFS variables that are defined in my Release steps identified by:

$(CRMUrl),$(CRMOrg), $(CRMSolution) etc.

To see how these are implemented this site has a good write-up.

Step 2 the last step is to publish the workflow:


That does it except for all the rest of the setup work you must do to allow it to push through all your environments.

I hope this helps someone


Until then keep scripting



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 )

Facebook photo

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

Connecting to %s