15 Sep 2016 | Dynamics CRM | Dynamics CRM Online | Yeoman | npm | nodejs | generator-nullfactory-xrm
I've previously experimented on creating a simplified way of maintaining CRM solutions in source control. While I was quite happy with the end result, the process of setting up the projects, scripts and post-build steps was a little bit tedious.
This is where Yeoman code generator comes in. Yeoman is a very popular javascript based scaffolding engine that enables setting up new projects a breeze. I created my own custom generator that would help me to kick start new CRM solutions quickly. You can find the end product here: https://www.npmjs.com/package/generator-nullfactory-xrm
First, install Yeoman and generator-nullfactory-xrm using npm.
npm install -g yo
npm install -g generator-nullfactory-xrm
Then generate your new project:
yo nullfactory-xrm
Template questions and their purpose:
The visual studio solution filename.
The prefix for the projects generated. This can be an organization name or preferred convention.
This is the source CRM server url. Example:[https://sndbx.crm6.dynamics.com](https://sndbx.crm6.dynamics.com)
The username used to connect to the source CRM server.
The password for the above account.
The name of the CRM solution to be extracted.
Specifies if a new project should be created to manage the web resouces.
Specifies if a new plugin project should be created.
Start off by updating the packages for the Nullfactory.Xrm.Tooling
project. Open up the Package Manager Console
in Visual Studio and execute the following command:
Update-Package -reinstall -Project Nullfactory.Xrm.Tooling
Next, install the Microsoft.Xrm.Data.PowerShell
powershell module. On a Windows 10 or later, do this by executing the included powershell script Nullfactory.Xrm.Tooling\_Install\Install-Microsoft.Xrm.Data.PowerShell.ps1
or manually running the following command:
Install-Module -Name Microsoft.Xrm.Data.PowerShell -Scope CurrentUser
Anytime the CRM solution needs to be synchronized back to the project, execute the script located at Nullfactory.Xrm.Tooling\Scripts\Sync-CrmSolution.Param.ps1
.
Edit the mapping file to map to the appropriate resource project. They are located in the Nullfactory.Xrm.Tooling\Mapping
folder.
More information on the structure of the mapping file can be found here
The repackaging the extracted solution is integrated as a post-build step of the solution class library. Simply build it to output both a managed as well as unmanaged CRM solution package.
I think I did pretty good for my first generator and hope to continue to evolve it as I learn more about the templating engine.
Here are some ideas that I have floating around: * The ability to add multiple CRM solutions in one go. * The ability to rename the Plugin and WebResources Project * Add new projects after the initial project structure has been generated. * Refactor the script to better re-use components.
The generator is hosted in GitHub. Please feel free to fork and hack away at it. I would also appreciate any feedback you might have.