Skip to content

UsingTheModelsBuilder

Stephan edited this page Jun 27, 2014 · 4 revisions

The models builder can be used in different modes:

  • Live models
  • AppCode models
  • AppData models
  • Visual Studio

Pure Live models

Requires that the Site Integration package is installed, either via NuGet or as an Umbraco package, and that Live models are enabled (see Site Integration Configuration).

With Live models, models are generated and compiled on the fly, in memory, at runtime. You cannot see the code of the models, and they are available in views exclusively. This is for people who exclusively use the Umbraco back-end, and probably do not write controllers anyway. Whenever a content type is modified, models are re-generated without restarting Umbraco (in the same way .cshtml views are recompiled).

AppCode models

Requires that the Site Integration package is installed, either via NuGet or as an Umbraco package, and that App_Code models are enabled (see Site Integration Configuration).

With App_Code models, models must be explicitely generated via the Zbu.ModelsBuilder dashboard in the developer back-end section. When models generation is triggered, model files are created in the ~/App_Data/Models folder. Then, a ~/App_Code/build.models file is created or touched, in order to cause Umbraco to compile the model files. Each time models are generated, Umbraco restarts. Whenever a content type is modified, models must be manually generated.

If there are some filename.cs files in ~/App_Data/Models, the models builder will parse them for instructions (see Models Generation Configuration).

Dll models

Requires that the Site Integration package is installed, either via NuGet or as an Umbraco package, and that Dll models are enabled (see Site Integration Configuration).

With Dll models, everything works as with App_Code models, but the ~/App_Code/build.models file is never generated. Instead, a DLL named after the models namespace is generated in ~/bin. Each time models are generated, Umbraco restarts. Whenever a content type is modified, models must be manually generated.

AppData models

Requires that the Site Integration package is installed, either via NuGet or as an Umbraco package, and that App_Data models are enabled (see Site Integration Configuration).

With App_Data models, everything works as with App_Code models, but the ~/App_Code/build.models file is never generated. This means that models are never compiled. You need to explicitely copy those files to App_Code, or to your Visual Studio solution, for them to get compiled. This is the way to "just generate models".

Live App_Code/Dll models

When App_Code or Dll models are configured, and Live models are also configured, then everything works as with App_Code or Dll models, and in addition models are automatically re-generated every time a content type (or data type) is modified. Which restarts Umbraco. So you don't need to go and press the button, but Umbraco may keep restarting. Up to you.

Visual Studio

Requires that the Site Integration package is installed, either via NuGet or as an Umbraco package, and that the API is enabled (see Site Integration Configuration). Requires that the Visual Studio Extension is installed.

Then you need to:

  • Go to Tools | Options | Zbu | ModelsBuilder Options and configure the url to your website (eg http://www.example.com), and a logon and password for an Umbraco user that has permission to access the developer section.
  • Create a folder in your solution -- pick your own name. Within that folder, create a CSharp file -- again, pick your own name. The file can contain code, or just be empty. Edit the properties of the file and set the Custom tool value to ZbuModelsBuilder. Save the file, or right-click and Run Custom Tool. New files should appear underneath the file.

If there are some filename.cs files in the models folder, the models builder will parse them for instructions (see Models Generation Configuration).

If you generate models in the main site project, where the Site Integration package is already installed, then that is all you need. If you generate models in a separate library project, you must reference some libraries by installing the Libraries project in order to build the models.