Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve Morgan 1348 posts 4457 karma points c-trib
    Apr 14, 2016 @ 14:20
    Steve Morgan
    0

    Umbraco via Visual Studio & Nuget - models.generated.cs not included by default

    Hi,

    Since the latest version new projects in VS have the model builder enabled by default when installing from Nuget.

    Umbraco is creating templates with the model included

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.MODELNAME> 
    

    But because the /Models/models.generated.cs file is not included in the project by default nodes using these templates throw errors.

    Apologies if I've missed it but shouldn't this be documented somewhere or the model builder not enabled by default if this file can't be include in the nuget package? I can see this confusing people (it confused me at least!).

    Steve

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 14, 2016 @ 17:21
    Jan Skovgaard
    0

    Hi Steve

    If it helps there is some documentation about the models builder (v3+), here https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Umbraco.ModelsBuilder

    I'm still new to the modelsbuilder but by default it should be set to "PureLive" mode, which as I understand it, means that models should be generated on the fly without one needing to do anything in order to be able to access the data. This I think is targeted towards those who don't intend to ever opening up Visual Studio in order to work on their Umbraco site.

    Not sure whether those files need to be included in the VS project when doing initial builds etc. - I think it should just work out of the box but if you don't change the mode to something else...But I could be wrong here since I'm still a n00b...I just don't recall seeing any error doing a vanlilla Umbraco installation some time ago...So wondering if you modified the configuration to use another mode, which is then the cause of the errors you're seeing?

    /Jan

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Apr 15, 2016 @ 08:31
    Steve Morgan
    0

    Hi Jan,

    No, not changing any configs - just a fresh VS solution - nuget in Umbraco and any any new doc types created with a template are created with the model referenced.

    When you open these in VS they have the red squigglies because the models.generated.cs file is not included in the solution.

    On hover you obviously get (which gives you a clue I guess):

    The type or namespace name 'MODELNAME' does not exist in the namespace 'Umbraco.Web.PublishedContentModels' (are you missing an assembly reference?).

    I've no idea if this is easy to do but including this in the project on the nuget install would ensure there's no problem. I say this just because I wasn't sure where to find this and I'm sure others will have this issue.

    Not sure it's right to do but I've created an issue.

    http://issues.umbraco.org/issue/U4-8333

    Steve

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Apr 15, 2016 @ 09:15
    Steve Morgan
    1

    Actually reading this post

    http://www.zpqrtbnk.net/posts/purelive-models-introduction

    It suggests you shouldn't include this file.

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft