Skip to content

EBG ‐ Integrating The Early Bound Generator Into Your Build Pipeline

Daryl LaBar edited this page Nov 28, 2023 · 1 revision

Running Via the Command Line PAC

  1. Copy the contents of the DLaB.EarlyBoundGeneratorV2 in the XrmToolBox Plugins directory (Default: C:\Users{UserName}\AppData\Roaming\MscrmTools\XrmToolBox\Plugins\DLaB.EarlyBoundGeneratorV2)
  2. Paste the entire directory into the latest version of PAC Tools directory (C:\Users{UserName}\AppData\Local\Microsoft\PowerAppsCli\Microsoft.PowerApps.CLI.X.X.X\tools). This will end up with a \tools\DLaB.EarlyBoundGeneratorV2 directory in the PAC directory.
  3. Move the DLaB.ModelBuilderExtensions.dll up a directory from the \tools\DLaB.EarlyBoundGeneratorV2 directory to the tools directory
  4. Create an AUTH in the PAC if it doesn't already exist (Example using App/Secret: PAC auth create --name {NAME} --tenant {TENENT_ID} --applicationId {APP_ID} --clientSecret {APP_SECRET} --url https://{ORG_URL_NAME}.crm.dynamics.com/)
  5. Run the command line of the tool the Early Bound Generator spits out (PAC modelbuilder build --outdirectory {OUTPUT_DIRECTORY} --settingsTemplateFile {PATH_TO_builderSettings.json})

Early Bound Generator V1

Please note Everything below this line was written for the CrmSvcUtil version of the Early Bound Generator (EBG V1) This may not apply to the PAC Modelbuilder version


Build Pipeline Integration

Key Pieces

  • GUI DLaB.EarlyBoundGenerator.Settings.xml file - This is the file defined in the Settings path of the GUI. It stores the serialized settings that the Early Bound Generator uses to populate the UI and to generate the item, the CrmSvcUtil.exe.config. The path of which is also used to resolve relative paths for generation of the output files. This can be renamed if desired.
  • CrmSvcUtil Folder - By default this comes nested in the Plugins folder of the XrmToolBox. The path is configurable so it can be placed wherever you'd like as long as it includes the required files.
  • CrmSvcUtil.exe.config - This is recreated each time a request is made in the EBG UI to regenerate classes.
  • Command Line - The command line is spit out (minus the password) in the Text Box in the UI when regenerating classes, as well as in the main class file for each type (Actions.cs, Entities.cs/CrmContext.cs, OptionSets.cs)

Recommendation for Manual Generation in a "Team Safe" way

  1. Define your Settings.xml file.
    1. First copy the default DLaB.EarlyBoundGenerator.Settings.xml to a folder within your source control map on your machine. It is recommended that this folder is below the VS solution file that uses early bound entities so if someone gets latest on the solution folder, they'll get the latest generator settings.
    2. Run the Early Bound Generator in the XrmToolBox, connecting to the dev org and selecting the settings file from the source control folder from 1.i. The Early Bound Generator will tie the generator setting to each org, so if you have multiple clients, each client can have different settings.
    3. Configuring the settings however you'd like until you're satisfied. Be sure to have the output paths be relative paths, relative to the location of the settings.xml file. from 1.i.
    4. Generate all entities/actions/option sets. Verify the output is correct and that the entities/project files in your VS solution have been correctly updated.
    5. Important Close the Early Bound Generator in XrmToolbox to save the settings to your .xml file.
  2. Communicate to the Team these steps for how to generate the files.
    1. Always get the latest version of the settings.xml from 1.i before opening the Early Bound Generator.
    2. Connect to the dev org from which entities should be generated from. Double check that the settings file is the correct file from source control.
    3. Tweak any settings as needed (add a new entity/action to the white list, etc).
    4. Generate all.
    5. Close the Early Bound Generator and check in the changes.
    6. Enjoy an early bound world!

Recommendation for Auto "Pipeline" Generation.

Follow the steps from the Recommendation for Manual Generation in a "Team Safe" way section above, except that the location of the CrmSvcUtil folder should be moved to a folder in source control (Or you can use the EBG.API Nuget file if you can't bring yourself to check in dlls and an exe into source control. You'll need to copy over the CrmSvcUtil.exe.config file if you do this though as a part of your build process, once the nuget file is downloaded, but before the files are generated). Then your build process will need to run the command lines that are normally ran by the GUI, or you can use the powershell method below.

Any future configurations can be made directly to the CrmSvcUtil.exe.config, or via the GUI by running the tool once after making the desired updates.

PowerShell Command

If you need to run this as a part of your build, use this PowerShell script:

param(
   [string]$crmServerUrl,
    [string]$targetDir,
   [string]$toolsDir
)

$arguments=@("/url:`"$crmServerUrl`"",
"/namespace:`"Scam.Xrm.EntityWrappers`"",
"/out:`"$targetDir\CrmServiceContext.cs`"",
"/servicecontextname:`"CrmServiceContext`"",
"/codecustomization:`"DLaB.CrmSvcUtilExtensions.Entity.CustomizeCodeDomService,DLaB.CrmSvcUtilExtensions`"",
"/codegenerationservice:`"DLaB.CrmSvcUtilExtensions.Entity.CustomCodeGenerationService,DLaB.CrmSvcUtilExtensions`"",
"/codewriterfilter:`"DLaB.CrmSvcUtilExtensions.Entity.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions`"",
"/namingservice:`"DLaB.CrmSvcUtilExtensions.NamingService,DLaB.CrmSvcUtilExtensions`"",
"/metadataproviderservice:`"DLaB.CrmSvcUtilExtensions.Entity.MetadataProviderService,DLaB.CrmSvcUtilExtensions`""
)

Start-Process -FilePath "crmsvcutil.exe" -WorkingDirectory "$toolsDir" -ArgumentList $arguments -Wait

Azure DevOps Pipeline Tasks

  1. Install the EBG DevOps Tools from the Visual Studio marketplace to your Azure DevOps organization.
  2. Add the EBG DevOps Tools tasks to your pipeline.
    1. Add the EBG DevOps Tool Installer task to your pipeline first.
      1. This task is a pre-requisite to the Early Bound Generator task as it sets the required versions of the dependencies.
      2. Optionally override the version of DLaB.Xrm.EarlyBoundGenerator.Api (1.2021.12.12) to match the Early Bound Generator Version from your DLaB.EarlyBoundGenerator.Settings.xml file. Alternatively, you may specify latest to use the latest version.
    2. Add the Early Bound Generator task to your pipeline.
      1. This task performs the generation of the Early Bound XRM Classes (Actions, Entities and Option Sets) by invoking CrmSvcUtil.exe via DLaB.Xrm.EarlyBoundGenerator.Api.
      2. The Connection String must follow the conventions outlined in the Microsoft Dataverse documentation.
      3. The Settings Path should point to the DLaB.EarlyBoundGenerator.Settings.xml.
      4. The Creation Type allows you to specify which type of Early Bound XRM Classes to generate (Actions, Entities, Option Sets or All).