generators - phuocle/Dynamics-Crm-DevKit GitHub Wiki

CLI Task: generators

URL: https://github.com/phuocle/Dynamics-Crm-DevKit/wiki/cli/generators

Overview

The generators task generates C# late-bound classes, TypeScript form declarations, or WebAPI client code from Dynamics 365 / Dataverse metadata.

Command Line Syntax

DynamicsCrm.DevKit.Cli.exe /conn:"YourConnectionString" /json:"DynamicsCrm.DevKit.Cli.json" /type:generators /profile:"ProfileName"

Parameters

Required Parameters

Parameter Description Example
/conn Dynamics 365 connection string "/conn:AuthType=Office365;Url=https://yourorg.crm.dynamics.com;[email protected];Password=password"
/json Path to DynamicsCrm.DevKit.Cli.json file "/json:DynamicsCrm.DevKit.Cli.json"
/type Task type (must be "generators") "/type:generators"
/profile Profile name from json file "/profile:ACCOUNT"

Optional Parameters

Parameter Description Example
/sdklogin Use SDK login dialog "/sdklogin:yes"

JSON Configuration

Add a generators section in your DynamicsCrm.DevKit.Cli.json:

{
  "generators": [
    {
      "profile": "ACCOUNT",
      "type": "CSharp",
  "rootfolder": "Dev.DevKit.Shared\\Entities",
   "rootnamespace": "Dev.DevKit.Shared.Entities",
      "entities": "account,contact"
    },
    {
"profile": "JSFORM",
      "type": "JsForm",
      "rootfolder": "Dev.DevKit.WebResource\\entities",
      "rootnamespace": "Dev.DevKit",
      "entities": "*"
    },
    {
      "profile": "JSWEBAPI",
      "type": "JsWebApi",
  "rootfolder": "Dev.DevKit.WebResource\\entities",
      "rootnamespace": "Dev.DevKit",
      "entities": "folder"
    }
  ]
}

JSON Properties

Property Type Required Description
profile string Yes Profile identifier
type string Yes Generator type: "CSharp", "JsForm", or "JsWebApi"
rootfolder string Yes Output folder path (relative to json file)
rootnamespace string Yes Root namespace for generated code
entities string Yes Entity filter: "*" (all), "folder" (existing files), or comma-separated list

Generator Types

1. CSharp - Late-Bound Classes

Generates C# late-bound entity classes with:

  • All entity attributes
  • OptionSet enumerations
  • Relationships
  • FormattedValue properties
  • Strong typing

Output: {EntityName}.generated.cs

Example:

namespace Dev.DevKit.Shared.Entities
{
    public partial class Account : EntityBase
    {
 public string Name { get; set; }
        public EntityReference PrimaryContactId { get; set; }
        // ... more properties
    }
}

2. JsForm - TypeScript Form Definitions

Generates TypeScript definitions for Dynamics 365 forms with:

  • Form sections and tabs
  • Field controls
  • Navigation items
  • Grid controls
  • Complete IntelliSense support

Output: {EntityName}.form.js and {EntityName}.d.ts

Example:

declare namespace DevKit {
    namespace FormAccount {
        interface Body {
    Name: DevKit.Controls.String;
  PrimaryContactId: DevKit.Controls.Lookup;
        }
    }
}

3. JsWebApi - WebAPI Client

Generates TypeScript WebAPI client code with:

  • CRUD operations
  • Retrieve formatted values
  • OData queries
  • Strong typing

Output: {EntityName}.webapi.js and {EntityName}.d.ts

Example:

DevKit.AccountApi = function(e) {
    // WebAPI implementation
};

Entity Filter Options

Option 1: All Entities ("*" or "all")

"entities": "*"

Generates code for ALL entities in the system (may take time for large systems).

Option 2: Folder-Based ("folder")

"entities": "folder"

Only updates existing files in the rootfolder directory.

Option 3: Specific Entities (Comma-Separated)

"entities": "account,contact,lead,opportunity"

Generates code only for specified entities.

Option 4: Empty or Null (Same as "folder")

"entities": ""

Same behavior as "folder" option.

Examples

Example 1: Generate C# Late-Bound Classes for Specific Entities

DynamicsCrm.DevKit.Cli.exe ^
  /conn:"AuthType=Office365;Url=https://contoso.crm.dynamics.com;[email protected];Password=pass" ^
/json:"DynamicsCrm.DevKit.Cli.json" ^
  /type:generators ^
  /profile:"CSHARP"

JSON:

{
  "generators": [
    {
      "profile": "CSHARP",
      "type": "CSharp",
      "rootfolder": "Entities",
      "rootnamespace": "MyProject.Entities",
      "entities": "account,contact,lead"
    }
  ]
}

Example 2: Generate TypeScript Form Definitions for All Entities

DynamicsCrm.DevKit.Cli.exe ^
  /conn:"AuthType=Office365;Url=https://contoso.crm.dynamics.com;[email protected];Password=pass" ^
  /json:"DynamicsCrm.DevKit.Cli.json" ^
  /type:generators ^
  /profile:"FORMS"

JSON:

{
  "generators": [
    {
    "profile": "FORMS",
      "type": "JsForm",
      "rootfolder": "WebResources\\forms",
      "rootnamespace": "MyProject",
      "entities": "*"
    }
  ]
}

Example 3: Update Existing WebAPI Files

DynamicsCrm.DevKit.Cli.exe ^
  /conn:"AuthType=Office365;Url=https://contoso.crm.dynamics.com;[email protected];Password=pass" ^
  /json:"DynamicsCrm.DevKit.Cli.json" ^
  /type:generators ^
  /profile:"WEBAPI"

JSON:

{
  "generators": [
    {
      "profile": "WEBAPI",
    "type": "JsWebApi",
      "rootfolder": "WebResources\\webapi",
      "rootnamespace": "MyProject",
      "entities": "folder"
    }
  ]
}

Example 4: Multiple Profiles in One JSON

{
  "generators": [
    {
      "profile": "BACKEND",
      "type": "CSharp",
      "rootfolder": "Backend\\Entities",
      "rootnamespace": "MyProject.Backend.Entities",
      "entities": "account,contact"
    },
    {
  "profile": "FRONTEND_FORMS",
      "type": "JsForm",
      "rootfolder": "Frontend\\forms",
      "rootnamespace": "MyProject.Frontend",
    "entities": "account,contact"
    },
    {
      "profile": "FRONTEND_API",
      "type": "JsWebApi",
  "rootfolder": "Frontend\\webapi",
    "rootnamespace": "MyProject.Frontend",
    "entities": "account,contact"
    }
  ]
}

Output

The task outputs:

  • ? CREATED - New files created
  • ? UPDATED - Existing files updated
  • ?? DO_NOTHING - No changes needed
  • ? ERROR - Entity not found

File Control Comments

For TypeScript files, you can control generation with comments:

//{'UseForm':true,'UseWebApi':true,'Version':'3.44.44.44'}
  • UseForm: Generate form definitions
  • UseWebApi: Generate WebAPI client
  • Version: Track generator version

Common Issues

Issue: Entity not found

Solution: Verify entity logical name is correct and exists in your environment

Issue: Files not updating

Solution: Check the entities filter and rootfolder path are correct

Issue: TypeScript IntelliSense not working

Solution: Ensure devkit.d.ts file exists in the same folder

Performance Tips

  1. Use specific entity lists instead of "*" for faster generation
  2. Use "folder" to only update existing files
  3. Separate profiles for different entity groups

Related Tasks

See Also

⚠️ **GitHub.com Fallback** ⚠️