Umbraco.Community.ModelAliases 1.0.0

dotnet add package Umbraco.Community.ModelAliases --version 1.0.0
                    
NuGet\Install-Package Umbraco.Community.ModelAliases -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Umbraco.Community.ModelAliases" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Umbraco.Community.ModelAliases" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Umbraco.Community.ModelAliases" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Umbraco.Community.ModelAliases --version 1.0.0
                    
#r "nuget: Umbraco.Community.ModelAliases, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Umbraco.Community.ModelAliases@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Umbraco.Community.ModelAliases&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Umbraco.Community.ModelAliases&version=1.0.0
                    
Install as a Cake Tool

Model Aliases

Downloads NuGet GitHub license

Property alias constants for your Umbraco Models Builder models, so ContentPage.Aliases.Title is "title" and you never type an alias string by hand again.

What it does

Models Builder gives you a typed property for each field (Model.Title), but a lot of Umbraco code still asks for the alias as a string: Value<T>("title"), HasValue("title"). Those strings are easy to mistype and nothing tells you when they go stale. This package adds a nested Aliases class to every generated model, with one const string per property:

// Before: a typo compiles, and quietly returns 0
var width = media.Value<int>("umbracoWidht");

// After: a typo is a build error
var width = media.Value<int>(Image.Aliases.UmbracoWidth);

The constants are written whenever Models Builder generates your models, into a separate <Model>.Aliases.gen.cs file beside each stock <Model>.generated.cs. Your existing models are not edited.

Benefits

  • No magic strings. A mistyped alias fails the build instead of returning an empty value at runtime.
  • IntelliSense. Type ContentPage.Aliases. and pick from the list.
  • Stays in step with your content types. Rename or remove a property and every place that used its constant stops compiling.
  • Everything the model exposes, including properties from compositions and base types.
  • Real constants, so they work in switch case labels and attribute arguments.
  • No setup. Nothing to configure and nothing in your existing models to change.

Installation

Add the package to the Umbraco website that runs Models Builder (any v17 release, from 17.0.0):

dotnet add package Umbraco.Community.ModelAliases

Usage

  1. Set Umbraco:CMS:ModelsBuilder:ModelsMode to SourceCodeManual or SourceCodeAuto.
  2. In the back office go to Settings, Models Builder, and press Generate models.
  3. Rebuild, then use the constants. They sit in your models' namespace:
@if (Model.HasValue(ContentPage.Aliases.Banner))
{
    <p>@Model.Value<string>(ContentPage.Aliases.Title)</p>
}

The constant is named after the property, so alias pageTitle becomes Aliases.PageTitle.

Good to know

  • Commit the *.Aliases.gen.cs files with your other generated models. A site that only consumes pre-built models (ModelsMode: Nothing, as on Umbraco Cloud) gets them that way.
  • Do not rename the files to end .generated.cs: Umbraco deletes any of those it did not write itself.
  • A property named Aliases, or two properties that end up with the same name, stops generation with a clear message. Change one of the aliases.
  • Requires Umbraco 17 (any release from 17.0.0), on .NET 10. It is not yet available for Umbraco 18.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 0 11/13/2026
0.1.0 0 11/13/2026