![]() |
VOOZH | about |
dotnet tool install --global Kontent.Ai.ModelGenerator --version 10.2.0
dotnet new tool-manifestif you are setting up this repo
dotnet tool install --local Kontent.Ai.ModelGenerator --version 10.2.0
#tool dotnet:?package=Kontent.Ai.ModelGenerator&version=10.2.0
nuke :add-package Kontent.Ai.ModelGenerator --version 10.2.0
👁 NuGet
👁 License
👁 Build & Test
👁 codecov
👁 Contributors
👁 Last commit
👁 GitHub Issues
👁 Stack Overflow
👁 Discord
This utility generates strongly-typed record-based models for the Kontent.ai Delivery SDK for .NET (v19+).
This version targets the modern Delivery SDK (v19+) only. If you need to generate models for the legacy Delivery SDK (v18.x and earlier), the Management SDK, or Extended Delivery, use the previous stable release.
The generated models use modern C# features and patterns:
record types with { get; init; } accessorsRichTextContent, Asset, TaxonomyTerm, IEmbeddedContentContentTypeCodename attribute - For source-generated TypeProvider discoveryContentTypeCodename constant - Access the content type codename at compile time (usable in switch/case labels, attribute arguments, and other contexts that require a compile-time constant) without reflectionIf an element codename would produce a property or constant that collides with the built-in ContentTypeCodename constant (e.g., an element named content_type_codename or content_type), the element's member is automatically prefixed with an underscore (_ContentTypeCodename) to avoid conflicts. The [JsonPropertyName] attribute ensures deserialization still works correctly.
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.
dotnet tool install -g Kontent.Ai.ModelGenerator
KontentModelGenerator --environmentId "<environmentId>" \
[--namespace "<custom-namespace>"] \
[--outputdir "<output-directory>"] \
[--baseRecord "<base-record-name>"] \
[--nullability strict|semantic]
dotnet new tool-manifest
dotnet tool install Kontent.Ai.ModelGenerator
dotnet tool run KontentModelGenerator --environmentId "<environmentId>" \
[--namespace "<custom-namespace>"] \
[--outputdir "<output-directory>"] \
[--baseRecord "<base-record-name>"] \
[--nullability strict|semantic]
Self-contained apps are an ideal choice for machines without any version of .NET installed.
Latest release: Download
<details> <summary>Building a self-contained binary for a specific platform</summary>
src/Kontent.Ai.ModelGeneratordotnet build -r <RID> to build (see the list of all RIDs)dotnet publish -c release -r <RID> to publish</details>
| Short key | Long key | Required | Default value | Description |
|---|---|---|---|---|
-i |
--environmentId |
Yes | null |
A GUID that can be found in Kontent.ai → Environment settings → Environment ID |
-n |
--namespace |
No | KontentAiModels |
A name of the C# namespace |
-o |
--outputdir |
No | ./ |
An output folder path |
-t |
--withtypeprovider |
No | false |
(Obsolete) TypeProvider is now source-generated by the Delivery SDK. |
-b, -r |
--baseRecord |
No | null |
If provided, a base record will be created and all generated records will derive from it via partial extender records |
--nullability |
No | strict |
Either strict or semantic. See Nullability mode. |
Short keys such as -n "MyModels" are interchangeable with the long keys --namespace "MyModels". Other possible syntax is -n=MyModels or --namespace=MyModels. Parameter values are case-insensitive. To see all aspects of the syntax, see the MS docs.
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.
There are two ways of configuring advanced Delivery SDK options (such as secure API access, preview API access, and others):
Command-line arguments:
--DeliveryOptions:UseSecureAccess true --DeliveryOptions:SecureAccessApiKey <SecuredApiKey>
- suitable for the standalone app release
Generated file: Article.cs
// <auto-generated>
// This code was generated by Kontent.ai model generator 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.
// To extend this record, create a separate partial record with the same name.
// </auto-generated>
#nullable enable
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Kontent.Ai.Delivery.Abstractions;
using Kontent.Ai.Delivery.Attributes;
using Kontent.Ai.Delivery.ContentItems;
using Kontent.Ai.Delivery.ContentItems.RichText;
using Kontent.Ai.Delivery.SharedModels;
namespace KontentAiModels;
[ContentTypeCodename("article")]
public partial record Article
{
public const string BodyCopyCodename = "body_copy";
public const string CustomTrackingCodeCodename = "custom_tracking_code";
public const string PersonasCodename = "personas";
public const string PostDateCodename = "post_date";
public const string RelatedArticlesCodename = "related_articles";
public const string TeaserImageCodename = "teaser_image";
public const string TitleCodename = "title";
public const string UrlPatternCodename = "url_pattern";
public const string ContentTypeCodename = "article";
[JsonPropertyName("body_copy")]
public RichTextContent? BodyCopy { get; init; }
[JsonPropertyName("custom_tracking_code")]
public string? CustomTrackingCode { get; init; }
[JsonPropertyName("personas")]
public IEnumerable<TaxonomyTerm>? Personas { get; init; }
[JsonPropertyName("post_date")]
public DateTimeContent? PostDate { get; init; }
[JsonPropertyName("related_articles")]
public IEnumerable<IEmbeddedContent>? RelatedArticles { get; init; }
[JsonPropertyName("teaser_image")]
public IEnumerable<Asset>? TeaserImage { get; init; }
[JsonPropertyName("title")]
public string? Title { get; init; }
[JsonPropertyName("url_pattern")]
public string? UrlPattern { get; init; }
}
The generator supports two nullability strategies for element properties via the --nullability flag:
strict (default)Every element property is generated as a nullable type — string?, RichTextContent?, IEnumerable<Asset>?, etc. This is the conservative default. It's also useful if you use the Delivery SDK's projection features (WithElements / WithoutElements) and want the type system to distinguish "not fetched" (null) from "fetched and empty" — projected-away elements surface as null at runtime.
public string? Title { get; init; }
public RichTextContent? BodyCopy { get; init; }
public IEnumerable<IEmbeddedContent>? RelatedArticles { get; init; }
semanticElement properties match the runtime semantics of the Delivery API: empty text, rich text and collection elements always come back populated, so they're generated as non-nullable with sensible default initializers. Numbers, dates and custom elements can be genuinely unset, so they remain nullable.
public string Title { get; init; } = string.Empty;
public RichTextContent BodyCopy { get; init; } = RichTextContent.Empty;
public IEnumerable<IEmbeddedContent> RelatedArticles { get; init; } = [];
public double? Rating { get; init; }
public DateTimeContent? PostDate { get; init; }
public string? CustomTrackingCode { get; init; }
When combined with projection (WithElements / WithoutElements), an omitted element surfaces as the type's default ("", [], RichTextContent.Empty) rather than null — so "not fetched" and "fetched and empty" look the same. That's fine if your code doesn't branch on that distinction; if it does, prefer strict.
--nullability semantic requires Delivery SDK 19.2.0+ (for RichTextContent.Empty). It will become the default in the next major version of the model generator.
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;
[ContentTypeCodename("article")]
public partial record Article
{
public const string TitleCodename = "title";
// ... other constants and properties
public const string ContentTypeCodename = "article";
[JsonPropertyName("title")]
public string? Title { get; init; }
}
Your custom file: Article.Custom.cs (your customizations)
namespace KontentAiModels;
public partial record Article
{
// Add computed properties
public string Slug => Title?.ToLowerInvariant().Replace(" ", "-") ?? string.Empty;
// Add custom methods
public bool IsPublished() => PostDate is { DateTime: var dt } && dt <= 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.
This version supports the modern Delivery SDK (v19+) only. For other use cases, use the previous stable release:
Found a bug or have a feature request? Open an issue. Pull requests are welcome!
We would like to express our thanks to the following people who contributed and made the project possible:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.2.0 | 150 | 5/5/2026 |
| 10.1.1 | 133 | 4/23/2026 |
| 10.1.0 | 115 | 4/21/2026 |
| 10.0.0 | 139 | 4/19/2026 |
| 10.0.0-beta-5 | 131 | 3/3/2026 |
| 10.0.0-beta-4 | 118 | 3/3/2026 |
| 10.0.0-beta-3 | 124 | 2/20/2026 |
| 10.0.0-beta-2 | 129 | 1/11/2026 |
| 10.0.0-beta | 229 | 10/26/2025 |
| 9.0.0 | 3,073 | 4/8/2025 |
| 8.4.0 | 6,032 | 12/12/2023 |
| 8.3.3 | 2,913 | 6/4/2023 |
| 8.3.2 | 489 | 5/18/2023 |
| 8.3.1 | 464 | 5/5/2023 |
| 8.3.0 | 534 | 4/20/2023 |
| 8.3.0-beta.6 | 241 | 4/13/2023 |
| 8.3.0-beta.3 | 221 | 2/16/2023 |
| 8.3.0-beta.2 | 210 | 2/16/2023 |
| 8.3.0-beta.1 | 220 | 2/16/2023 |
| 8.2.0 | 1,228 | 2/9/2023 |