This utility generates strongly-typed models based on Content Types in a Kentico Kontent project. The models are supposed to be used together with the Kentico Kontent Delivery SDK for .NET or Kentico Kontent Content Management SDK for .NET. Please read the documentation to see all benefits of this approach.
The recommended way of obtaining this tool is installing it as a .NET Core Global Tool.
- Run
dotnet tool install -g Kentico.Kontent.ModelGenerator
Then you can start using the KontentModelGenerator
command in the command-line right away.
Latest release: Download
Note: The application is self-contained. There's no need to install any version of .NET on your machine.
- Clone the repository
- Navigate to the
kontent-generators-net\src\KontentModelGenerator
folder - Run
dotnet build -r <RID>
to build the app - Run
dotnet publish -c release -r <RID>
to publish the app
See the list of all RIDs.
KontentModelGenerator.exe --projectid "<projectid>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider] [--structuredmodel] [--filenamesuffix "<suffix>"]
dotnet run --projectid "<projectid>" [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--withtypeprovider] [--structuredmodel] [--filenamesuffix "<suffix>"]
Parameter (single character variant) | Keyword variant | Required | Default value | Description |
---|---|---|---|---|
-p |
--projectid |
True | null |
A GUID that can be found in Kentico Kontent -> API keys -> Project ID |
-n |
--namespace |
False | KenticoKontentModels |
A name of the C# namespace |
-o |
--outputdir |
False | \. |
An output folder path |
-g |
--generatepartials |
False | null |
Generates partial classes for customizationfilenames |
-t |
--withtypeprovider |
False | true |
Indicates whether the CustomTypeProvider class should be generated (see Customizing the strong-type binding logic for more info) |
-s |
--structuredmodel |
False | false |
Generates IRichTextContent instead of string for rich-text elements. This enables utilizing structured rich-text rendering |
-f |
--filenamesuffix |
False | null |
Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs) |
-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 |
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.
using System;
using System.Collections.Generic;
using Kentico.Kontent.Delivery;
namespace KenticoKontentModels
{
public partial class CompleteContentType
{
public string Text { get; set; }
public string RichText { get; set; }
public decimal? Number { get; set; }
public IEnumerable<MultipleChoiceOption> MultipleChoice { get; set; }
public DateTime? DateTime { get; set; }
public IEnumerable<Asset> Asset { get; set; }
public IEnumerable<object> ModularContent { get; set; }
public IEnumerable<TaxonomyTerm> Taxonomy { get; set; }
public string UrlSlug { get; set; }
public string CustomElement { get; set; }
public ContentItemSystemAttributes System { get; set; }
}
}
KontentModelGenerator.exe --projectid "<projectid>" --contentmanagementapi [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--filenamesuffix "<suffix>"]
dotnet run --projectid "<projectid>" --contentmanagementapi [--namespace "<custom-namespace>"] [--outputdir "<output-directory>"] [--filenamesuffix "<suffix>"]
Parameter (single character variant) | Keyword variant | Required | Default value | Description |
---|---|---|---|---|
-p |
--projectid |
True | null |
A GUID that can be found in Kentico Kontent -> API keys -> Project ID |
-c |
--contentmanagementapi |
True | false |
Indicates that models should be generated for Content Management SDK |
-n |
--namespace |
False | KenticoKontentModels |
A name of the C# namespace |
-o |
--outputdir |
False | \. |
An output folder path |
-f |
--filenamesuffix |
False | null |
Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs) |
-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 |
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.
using System;
using System.Collections.Generic;
using KenticoCloud.ContentManagement.Models.Assets;
using KenticoCloud.ContentManagement.Models.Items;
using Newtonsoft.Json;
namespace KenticoKontentModels
{
public partial class CompleteContentType
{
public string Text { get; set; }
public string RichText { get; set; }
public decimal? Number { get; set; }
public IEnumerable<MultipleChoiceOptionIdentifier> MultipleChoice { get; set; }
public DateTime? DateTime { get; set; }
public IEnumerable<AssetIdentifier> Asset { get; set; }
public IEnumerable<ContentItemIdentifier> ModularContent { get; set; }
public IEnumerable<TaxonomyTermIdentifier> Taxonomy { get; set; }
public string UrlSlug { get; set; }
public string CustomElement { get; set; }
}
}
Check out the contributing page to see the best places to file issues, start discussions and begin contributing.
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!