Kontent.Ai.ModelGenerator 10.0.0-beta

This is a prerelease version of Kontent.Ai.ModelGenerator.
dotnet tool install --global Kontent.Ai.ModelGenerator --version 10.0.0-beta
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local Kontent.Ai.ModelGenerator --version 10.0.0-beta
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Kontent.Ai.ModelGenerator&version=10.0.0-beta&prerelease
                    
nuke :add-package Kontent.Ai.ModelGenerator --version 10.0.0-beta
                    

Kontent.ai model generator utility for .NET

Build & Test codecov Stack Overflow Discord

⚠️ BETA VERSION - Modern Delivery SDK ONLY

This beta version ONLY works with the modernized Kontent.ai Delivery SDK for .NET (v19.0.0-beta-2 and higher).

What this version supports:

  • Modern Delivery SDK (v19+) - Generates record-based models with modern types

What this version does NOT support:

Need the old version? If you're using the legacy Delivery SDK (v18.x), Management SDK, or Extended Delivery models, please use the previous stable release from the releases page.


This utility generates strongly-typed record-based models for the modern Kontent.ai Delivery SDK for .NET (v19+).

What's New in Modern Delivery Models

The generated models use modern C# features and patterns:

  • Records - Immutable record types with { get; init; } accessors
  • File-scoped namespaces - Clean, modern C# syntax
  • JSON attributes - [JsonPropertyName] for explicit property mapping
  • Modern types - RichTextContent, Asset, TaxonomyTerm, IEmbeddedContent
  • Single file per model - No .Generated.cs split files
  • Partial records - Easily extendable without modifying generated code
  • IElementsModel interface - For type-safe element access

Installation & Usage

The recommended way of obtaining this tool is installing it as a .NET Tool. You can install it as a global tool or per project as a local tool.

Global Tool
  • dotnet tool install -g Kontent.Ai.ModelGenerator
  • KontentModelGenerator --environmentid "<environmentId>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider <True|False>] [--baseclass "<base-class-name>"]
Local Tool
  • dotnet new tool-manifest to initialize the tools manifest (if you haven't done that already)
  • dotnet tool install Kontent.Ai.ModelGenerator (to install the latest version
  • dotnet tool run KontentModelGenerator --environmentId "<environmentId>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider <True|False>] [--baseclass "<base-class-name>"]

Standalone apps for Windows 🗔, Linux 🐧, macOS 🍎

Self-contained apps are an ideal choice for machines without any version of .NET installed.

Latest release: Download

  • KontentModelGenerator --environmentId "<environmentId>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider <True|False>] [--baseclass "<base-class-name>"]

To learn how to generate executables for your favorite target platform, follow the steps in the docs.

Parameters

Short key Long key Required Default value Description
-i --environmentId True null A GUID that can be found in Kontent.ai → Environment settings → Environment ID
-n --namespace False KontentAiModels A name of the C# namespace
-o --outputdir False \. An output folder path
-t --withtypeprovider False true Indicates whether the CustomTypeProvider class should be generated for model binding
-b --baseclass False null If provided, a base class type will be created and all generated classes will derive from that base class via partial extender classes

CLI Syntax

Short keys such as -t true are interchangable with the long keys --withtypeprovider true. Other possible syntax is -t=true or --withtypeprovider=true. Parameter values are case-insensitive, so you can use both -t=true and -t=True. To see all aspects of the syntax, see the MS docs.

Config file

These parameters can also be set via the appSettings.json file located in the same directory as the executable file. Command-line parameters always take precedence.

Advanced configuration (Preview API, Secure API)

There are two ways of configuring advanced Delivery SDK options (such as secure API access, preview API access, and others):

  1. Command-line arguments --DeliveryOptions:UseSecureAccess true --DeliveryOptions:SecureAccessApiKey <SecuredApiKey> (syntax)

  2. appSettings.json - suitable for the standalone app release

Generated Model Example

Generated file: Article.cs

// <auto-generated>
// This code was generated by a kontent-generators-net tool
// (see https://github.com/kontent-ai/model-generator-net).
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// For further modifications of the class, create a separate file with the partial class.
// </auto-generated>

using System.Collections.Generic;
using System.Text.Json.Serialization;
using Kontent.Ai.Delivery.Abstractions;
using Kontent.Ai.Delivery.ContentItems;
using Kontent.Ai.Delivery.ContentItems.RichText;
using Kontent.Ai.Delivery.SharedModels;

namespace KontentAiModels;

public partial record Article : IElementsModel
{
    [JsonPropertyName("title")]
    public string Title { get; init; } = default!;

    [JsonPropertyName("body_copy")]
    public RichTextContent BodyCopy { get; init; } = default!;

    [JsonPropertyName("post_date")]
    public DateTime? PostDate { get; init; }

    [JsonPropertyName("teaser_image")]
    public IEnumerable<Asset> TeaserImage { get; init; } = default!;

    [JsonPropertyName("related_articles")]
    public IEnumerable<IEmbeddedContent> RelatedArticles { get; init; } = default!;

    [JsonPropertyName("personas")]
    public IEnumerable<TaxonomyTerm> Personas { get; init; } = default!;

    [JsonPropertyName("url_pattern")]
    public string UrlPattern { get; init; } = default!;

    [JsonPropertyName("custom_tracking_code")]
    public string? CustomTrackingCode { get; init; }
}

Customizing Generated Models

Since the generated models are partial records, you can extend them by creating your own partial record file:

Generated file: Article.cs (auto-generated)

namespace KontentAiModels;

public partial record Article : IElementsModel
{
    [JsonPropertyName("title")]
    public string Title { get; init; } = default!;
    // ... other properties
}

Your custom file: Article.Custom.cs (your customizations)

namespace KontentAiModels;

public partial record Article
{
    // Add computed properties
    public string Slug => Title.ToLowerInvariant().Replace(" ", "-");

    // Add custom methods
    public bool IsPublished() => PostDate.HasValue && PostDate.Value <= DateTime.Now;

    // Add validation
    public bool IsValid() => !string.IsNullOrEmpty(Title) && BodyCopy != null;
}

The generator creates the base model, and you maintain customizations in separate files that won't be overwritten.

Need Management SDK or Legacy Delivery SDK Support?

This beta version only supports the modern Delivery SDK (v19+).

For other use cases, please use the previous stable release:

  • Legacy Delivery SDK (v18.x and earlier) models
  • Management SDK models
  • Extended Delivery models

Feedback & Contributing

Check out the contributing page to see the best places to file issues, start discussions and begin contributing.

Wall of Fame

We would like to express our thanks to the following people who contributed and made the project possible:

Would you like to become a hero too? Pick an issue and send us a pull request!

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
10.0.0-beta 167 10/26/2025
9.0.0 1,187 4/8/2025
8.4.0 5,761 12/12/2023
8.3.3 2,767 6/4/2023
8.3.2 436 5/18/2023
8.3.1 406 5/5/2023
8.3.0 472 4/20/2023
8.3.0-beta.6 188 4/13/2023
8.3.0-beta.3 169 2/16/2023
8.3.0-beta.2 164 2/16/2023
8.3.0-beta.1 172 2/16/2023
8.2.0 1,174 2/9/2023
8.1.1 1,239 1/5/2023
8.1.1-beta.4 185 10/27/2022
8.1.1-beta.3 176 10/27/2022
8.1.1-beta.2 182 10/27/2022
8.1.1-beta.1 186 10/27/2022
8.1.1-beta.0 183 10/27/2022
8.1.0 2,565 10/27/2022
8.0.0 1,657 8/4/2022
8.0.0-beta.3 223 8/2/2022
8.0.0-beta.2 204 8/1/2022