## Blog: Ramón Soto Mathiesen

### Background

Last CRMUG meeting, 2015-11-20 @ BRFkredit A/S, we heard that a lot of members had some difficulties in using the Microsoft Solution Packager tool.

As we at Delegate A/S have been using the tool since MS CRM 2011. This allows us to store the blueprint of our solutions in the code repositories, which then gives us the possibility to recreate a solution based on a code commit tag. By using this approach, it’s easier to maintain a solution as we are just creating software and hereby we can use known approaches to Application Lifecycle Management (ALM).

Therefore we would like to showcase a demo where we go from A to Z explaining every step. Code samples are available @ DG.CRMUG.SolutionPackager.

### What is it?

Microsoft defines SolutionPackager as a tool that can reversibly decompose a Microsoft Dynamics CRM compressed solution file into multiple XML files and other files so that these files can be easily managed by a source control system.

Folder structure and file naming scheme of the decomposed solution file: Solution component file reference

### Why use it?

• Application Lifecycle Management (ALM): By splitting the solutions customizations file into smaller parts which can be stored in a source control system, it gives us the possibility to re-create the solution at any given code commit which is almost indispensable when making/maintaining software solution.

• Multiple developers: It will also allow several people working with their own local solution and when a component is ready, then merge into the stagging solution which will be built and deployed to a TEST solution and afterwards to PROD.

### How to use it? (“correctly”)

Microsoft states: “When the SolutionPackager tool extracts the component files it will not overwrite existing component files of the same name if the file contents are identical. In addition, the tool honors the read-only attribute on component files producing a warning in the console window that particular files were not written. This enables the user to check out, from source control, the minimal set of files that are changing. The /clobber parameter can be used to override and cause read-only files to be written or deleted. The /allowWrite parameter can be used to assess what impact an extract operation has without actually causing any files to be written or deleted. Use of the /allowWrite parameter with verbose logging is effective”.

“This enables the user to check out, from source control, the minimal set of files that are changing. The /clobber parameter can be used to override and cause read-only files to be written or deleted”.

This is the main reason why TFS as source control is broken. If you have made a change to a file (Edit) and afterwards delete it, then TFS will complain that it can’t commit the edited file because it’s deleted (it’s stores both actions). Also there is the issue that TFS handles files that are read-only in the file system as committed and those who are not as checked-out. Unless you have to, please don’t use TFS as your source control.

It’s possible to make SolutionPackager work with TFS, but we discovered it made us change our natural code commit behavior (always commit before Extract/Pack even though code was not ready). If you want to set up TFS correctly, please follow this guide:

#### What we usually see

1. Add assemblies to DEV environment with Plug-in registration tool
• Assemblies are built with the Debug Profile
2. Manually extraction of Default.zip (not even a subset solution)
• Eventually save the hole .ZIP file in the source control system (SVN, TFS, …)
• Impossible to work with on a multiple DEV setup (diff of files in Visual Studio is not possible)
3. Deploy extracted .ZIP file from DEV -> TEST and go through Test Cases
• Finally deploy extracted .ZIP from DEV -> PROD

#### What we would like to see

1. Add assemblies to DEV environment with Plug-in registration tool (or better tooling :))
• Assemblies are built with the Debug Profile
2. Retrieve the unmanaged and managed subset solution from DEV (ex: FooBar.zip)
• Extract the solution to the source control system. Managed and Unmanaged extracted solution are saved in the same folder structure. It’s important to use the SolutionPackager mapping file in order to tell the tool that code (Plug-in and Workflows as well as Web Resources) are handled by a Visual Studio solution
• Merge diff locally before committing to the source control system as you would normally do when you are working on a software solution
3. Deploy the packed .ZIP from the source control system GIT -> TEST and go through Test Cases
• Ensure that Assemblies are built with the Release Profile
4. Finally deploy the packed .ZIP from the source control GIT -> PROD

#### Two very important remarks:

1. SolutionPackager doesn’t like long paths. Your source control folder should be as close to your drives root:
• Wrong: C:\Users\foo\Documents\Visual Studio 2015\DG.CRMUG\DG.CRMUG.FooBar.sln
• Correct: C:\git\DG.CRMUG\DG.CRMUG.FooBar.sln
2. When pointing to assemblies in the SolutionPackager mapping file, names must not have dots:
• Wrong:
• Correct:

### Samples based on Live Demo at CRMUG

We showcased the following scenario in order to point out how important it is not to deploy Debugged code to PROD:

1. Retrieve solution from DEV and Extract (Use Visual Studio to see Diff between CRM and GIT)
2. Deploy .ZIP file from DEV -> TEST and see it fail
• Show code where if Debug, code will fail
3. Pack from source control and deploy to TEST and see it succeed

Plug-in code that fails when compiled with the Debug Profile:

#### Deploy packed managed solution from GIT -> TEST with Daxif see it succeed

Remember to build the solution with the Release Profile (normally being handled by built script).

### Delegate.Daxif is released under our Open Source License

Due to this fact, I will blogpost on a weekly series of How to Daxif: … based on a specific topic each time and where we will show the features the tool has to offer in order to create more robust MS CRM solutions. Stay tuned.