Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1412 posts 3272 karma points c-trib
    Feb 19, 2016 @ 09:19
    Simon Dingley
    0

    v7.4.0 Umbraco Models Builder - Which Class to use in VS Solution

    I'm developing a site on the latest v7.4.0 which is a massive leap forward in terms of usability for me when fleshing out doctypes etc. I'm also now discovering the new ModelBuilder generated classes which are a great help allowing access to strongly typed models based on the current doctypes.

    My question is...which file should I reference in my solution? all.generated.cs or models.generated.cs - what is the difference or purpose of each?

    Thanks, Simon

  • Simon Dingley 1412 posts 3272 karma points c-trib
    Feb 19, 2016 @ 14:10
    Simon Dingley
    1

    I still don't know the difference however I have found that if I add one or the other to my solution and set the build action to None it works great. So much quicker for implementing templates and in conjunction with Umbraco Core Property Value Converters it adds another little increase in productivity!

  • Carl Jackson 139 posts 477 karma points
    Feb 19, 2016 @ 17:00
    Carl Jackson
    1

    Totally agree the two way integration with Property Value Convertes via either that plugin or any custom built ones is great. As long as you decorate them with :

    [PropertyValueType(typeof(xxxx))]
    

    Otherwise it doesn't work and you just get an "object".

  • Carl Jackson 139 posts 477 karma points
    Feb 19, 2016 @ 16:59
    Carl Jackson
    0

    Hi Simon.

    What have you got the "Umbraco.ModelsBuilder.ModelsMode" AppSetting as? I don't get these files when it is set to AppData I just get one file per doc type. in the App_Data/Models folder.

    I add each of these into the VS solution and re build when any changes are made, that has been working well for us for about a week now.

    Thanks

    Carl

  • Simon Dingley 1412 posts 3272 karma points c-trib
    Feb 22, 2016 @ 09:56
    Simon Dingley
    0

    Until you mentioned it I didn't actually know about the appsettings so they were just OOTB.

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="PureLive" />
    

    There is no need to rebuild, at least - I've not needed to. In fact, I have set the build action to "None" as I don't want it included in my build since it gets updated all the time and from memory as a result you end up with exceptions due to collisions between with compiled version.

    I have just found an answer to my original question:

    • models.generated.cs contains the generated code
    • models.hash contains a hash of the Umbraco content type structure
    • all.generated.cs contains the code that is compiled

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

    So I am actually referencing models.generated.cs in my solution.

    Cheers, Simon

  • Simon Dingley 1412 posts 3272 karma points c-trib
    Feb 22, 2016 @ 10:08
    Simon Dingley
    0

    To expand further on what happens if you allow one of the generated files to be compiled with your project, you get an exception along the lines of:

    Compiler Error Message: CS0433: The type 'Umbraco.Web.PublishedContentModels.Homepage' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\c249d10d\f1c4a21a\App_Web_all.generated.cs.8f9494c4.xpf2kfhd.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\c249d10d\f1c4a21a\assembly\dl3\489499f1\adce0a74_586dd101\MyProject.www.DLL'
    

    I completely understand why this happens and is simply fixed by setting the Build Action to None for that file.

  • Jeroen Breuer 4861 posts 12129 karma points MVP 3x admin c-trib
    Feb 22, 2016 @ 10:01
  • Zakhar 171 posts 397 karma points
    May 13, 2016 @ 14:33
    Zakhar
    0

    Hey guys,

    I'm using Umbraco 7.4.3 and I can't make the generated models to be recognized on my MVC views.

    I added following lines on my template :

    @using Umbraco.Web
    @using Umbraco.Web.Mvc
    @using Umbraco.Web.PublishedContentModels
    @inherits UmbracoViewPage<MyClass>
    

    But getting "The type or namespace name 'MyClass' could not be found (are you missing a using directive or an assembly reference?)" errors in VS error list.

    Although it actually works, the page loads and my document type properties load I don't have intellisense in my views and get loads of errors in VS.

    How can I make it work?

  • Simon Dingley 1412 posts 3272 karma points c-trib
    May 13, 2016 @ 14:38
    Simon Dingley
    0

    I seem to get this intermittently in v7.4.0 also and have to alternate by including either all.generated.cs or models.generated.cs in the project (not both). One of them usually works and the other doesn't and then it reverses. In all cases this never affects the site or the ability to build the project in VS.

    HTH, Simon

  • Zakhar 171 posts 397 karma points
    May 13, 2016 @ 15:38
    Zakhar
    0

    I can only make it to see my generated classes if I include all.generated.cs to the project with Build Action = Compile. But in this case I get "The type ... exists in both ..." exception when I try to browser the page.

    Also, did you have any luck with either <add key="Umbraco.ModelsBuilder.ModelsMode" value="Dll" /> or <add key="Umbraco.ModelsBuilder.EnableDllModels" value="true" /> in web.config? Neither seem to work, no dll is generated in bin folder.

    Thanks!

  • Simon Dingley 1412 posts 3272 karma points c-trib
    May 13, 2016 @ 15:50
    Simon Dingley
    0

    You must set the build action to 'None' for the very reason that you are getting an exception. You will end up with it compiled into your DLL as well as the dynamic version the site is already using.

    My appsettings are as follows:

        <add key="Umbraco.ModelsBuilder.Enable" value="true" />
        <add key="Umbraco.ModelsBuilder.ModelsMode" value="PureLive" />
    

    However things may have changed since the version I am using it on.

    Simon

  • Jeremy Pyne 106 posts 244 karma points MVP c-trib
    Oct 31, 2016 @ 21:04
Please Sign in or register to post replies

Write your reply to:

Draft