Umbraco Models Builder is an essential feature for any Umbraco website. Models Builder works by generating “strongly-typed” C# clasess that represent your Document Types in the CMS. You can then use these models in your controllers, views and other bespoke areas of your solution.
Although useful, Models Builder will output the current version of Umbraco in each class. Notice how the extract of a generated file below outputs 15.3.1+06a2a50
.
/// <summary>Home</summary>[PublishedModel("home")]public partial class Home : PublishedContentModel, IBasePage, IFooterControls, IHeaderControls, ISEocontrols, ISiteSettings{ // helpers #pragma warning disable 0109 // new is redundant [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder.Embedded", "15.3.1+06a2a50")] public new const string ModelTypeAlias = "home";
...}
The problem
Each time you update your Umbraco website, all of your generated files will change. However, there are a number of potential drawbacks:
- Pull Requests - Your team will need to review many generated files per project
- Pull Requests - Meaningful changes to document types may be harder to discover
- Scale - Developer team overhead in reviewing erroneous changes
The solution
It’s possible to prevent Umbraco from outputting the CMS version in generated files by updating appsettings.json
as follows:
{ "$schema": "https://json.schemastore.org/appsettings.json", "Umbraco": { "CMS": { "ModelsBuilder": { "IncludeVersionNumberInGeneratedModels": false } } }}
Now when you generate your models there will be no version in the output! 🚀