Dataverse early-bound generator for Power Platform, built as a .NET 7 CLI on top of Scriban templates.
- The CLI now reads
dataversegen.config.jsonfrom the current working directory. - If
ConnectionStringis missing, the app falls back to Windows Credential Manager and prompts for one. - The Scriban generator supports both
C#andtsoutput types. - Generation can run in single-file or multi-file mode.
- TypeScript generation also emits custom API request wrappers under
customapi/. - C# generation also emits custom API request wrappers under
customapi/. - Built-in templates are available through
TemplateName = "Main", and project templates can be copied under aTemplatesfolder. - Release builds are packaged into self-contained and framework-dependent ZIP archives by
build.ps1.
- The app loads Dataverse metadata for the entities listed in
Entities. - If
CustomApisis set, the custom API output is narrowed to the listed custom API unique names. - It validates the connection string when
EnableConnectionStringValidationis enabled. - It can throw when an entity from
Entitiesis missing ifThrowOnEntityNotFoundis enabled. TemplateEngine.Namecurrently supportsscriban.TemplateEngine.TypeacceptsC#orts.- When
TemplateEngine.IsSingleOutputistrue, the generator writes one output file per target. - When
TemplateEngine.IsSingleOutputisfalse, the generator writes multiple files per entity.
- Create
dataversegen.config.jsonin the directory where you want to run the generator. - Fill in the Dataverse connection string, entity names, namespace, and output directory.
- Run the CLI from that directory.
Example:
dotnet run --project DataverseGen.Cli{
"Entities": [
"account",
"contact"
],
"ConnectionString": "AuthType=ClientSecret;Url={url};ClientId={ClientId};ClientSecret={ClientSecret}",
"Namespace": "sad.Dataverse.DataAccess.Entities",
"OutDirectory": "Dataverse",
"TemplateName": "Main",
"TemplateDirectoryName": "Templates",
"EnableConnectionStringValidation": true,
"ThrowOnEntityNotFound": true,
"TemplateEngine": {
"IsSingleOutput": false,
"Name": "scriban",
"Type": "C#"
}
}{
"Entities": [
"account",
"contact"
],
"CustomApis": [
"newupdatestatus"
],
"ConnectionString": "AuthType=ClientSecret;Url={url};ClientId={ClientId};ClientSecret={ClientSecret}",
"Namespace": "sad.dataverse.ui.webresource",
"OutDirectory": "/src/dataversegen/",
"TemplateName": "dataverse-template",
"TemplateDirectoryName": "Templates",
"EnableConnectionStringValidation": true,
"ThrowOnEntityNotFound": true,
"TemplateEngine": {
"IsSingleOutput": true,
"Name": "scriban",
"Type": "ts"
}
}Custom API request wrappers are generated automatically for both C# and ts output.
Configuration is minimal:
- set
TemplateEngine.TypetoC#orts - keep the normal Dataverse connection string and output directory configuration
- optionally set
CustomApisto a list of custom API unique names to generate - make sure the environment contains
customapi,customapirequestparameter, andcustomapiresponsepropertymetadata
No extra flag is required in dataversegen.config.json and there is no separate custom API switch.
The generator reads the Dataverse metadata and writes custom API wrappers into:
<OutDirectory>/customapi/
Example TypeScript config that enables the feature:
{
"Entities": [
"account",
"contact"
],
"CustomApis": [
"newupdatestatus"
],
"ConnectionString": "AuthType=ClientSecret;Url={url};ClientId={ClientId};ClientSecret={ClientSecret}",
"Namespace": "sad.dataverse.ui.webresource",
"OutDirectory": "/src/dataversegen/",
"TemplateName": "dataverse-template",
"TemplateDirectoryName": "Templates",
"EnableConnectionStringValidation": true,
"ThrowOnEntityNotFound": true,
"TemplateEngine": {
"IsSingleOutput": true,
"Name": "scriban",
"Type": "ts"
}
}The generated wrappers use:
- the custom API unique name as the operation name
- request parameter names from Dataverse metadata
boundParametermetadata when the custom API is bound to an entity
If CustomApis is omitted or empty, all available custom APIs are generated.
Use CustomApis to limit custom API generation to specific uniquename values:
{
"CustomApis": [
"newupdatestatus",
"newregistercustomer"
]
}The names are matched against the Dataverse uniquename field, case-insensitively.
Entities- Dataverse schema names to generate.CustomApis- Custom API unique names to generate. If omitted or empty, all custom APIs are generated for the selected output type.ConnectionString- Dataverse connection string. If omitted, the CLI asks for it and stores it in Windows Credential Manager.Namespace- Namespace used in generated code.OutDirectory- Output folder for generated files.TemplateName- Template set to use.Mainselects the built-in templates.TemplateDirectoryName- Folder name that contains project templates.EnableConnectionStringValidation- Enables connection string validation. Default:false.ThrowOnEntityNotFound- Throws when an entity fromEntitiesis not found. Default:false.TemplateEngine.Name- Template engine name. Current value:scriban.TemplateEngine.Type- Output type. UseC#orts.TemplateEngine.IsSingleOutput- Controls single-file or multi-file generation.
Use the built-in template set with:
{
"TemplateName": "Main"
}Copy the Scriban template files into a Templates folder next to your config file:
MyProject
Templates
Dataverse-Template
...
dataversegen.config.json
Then reference the template folder name in the config:
{
"TemplateName": "Dataverse-Template",
"TemplateDirectoryName": "Templates"
}pwsh -NoProfile -File build.ps1publishes the CLI in Release mode.- The script creates both
includedotnetandnodotnetZIP packages underpublish/. - Release automation also publishes those ZIPs as GitHub Release assets.
- The solution targets
net7.0. - Run
dotnet test DataverseGen.slnafter changing generator logic. - The test project is
Tests/DataverseGen.Core.Tests.