Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

Copied to clipboard

Flag this post as spam?

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


  • Craig100 846 posts 1719 karma points
    Jan 30, 2017 @ 19:12
    Craig100
    0

    ModelsBuilder VS setup for multiple projects

    Spent all day trying to get ModelsBuilder useable in VS trying Umbraco as a WebSite and a WebApp. I have a myProject.Core (for custom code) and a myProject.Web (for Umb) projects. Have tried the "API" set up as described here: http://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder. It does what it says, in that it generates models under a.cs file in the myProject.Web project, but it doesn't cause any models to be created for the dataTypes. Also for it to work at all, you have to have the site actually running in debug mode or the custom tool can't find the site, which means you can't work on the code, create folders, files, etc. Very inconvenient or am I missing something important? This hasn't clarified anything for me either: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Builder-Modes

    I just have these in my web.config:-

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

    What is the best set up to get Models intellisense in VS so that you can have a separate project for custom code and how can you tell API mode has generated dataType models? I see so many different ways proposed it's super-confusing.

    Craig

  • David Peck 527 posts 1333 karma points c-trib
    Jan 30, 2017 @ 21:39
    David Peck
    0

    Hi Craig,

    My web.config is like this:

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

    The models builder won't create models for your data types. It will use a class like IHtmlString for the rich text editor, and for some packages they maybe setup to work correctly so as to use a class but if the models builder isn't sure then the property will be of type object. You will probably have to create a class (of the same name as your document type alias) to hangle it yourself e.g.:

    public partial class Footer
    {
        private IEnumerable<NavigationItemWithChildren> _navigation;
    
        [ImplementPropertyType("navigation")]
        public IEnumerable<NavigationItemWithChildren> Navigation
        {
            get
            {
                return _navigation = _navigation ?? this.GetPropertyValue<IEnumerable<IPublishedContent>>("navigation")
                                                        .Select(x => new NavigationItemWithChildren(x));
            }
        }
    }
    
  • David Peck 527 posts 1333 karma points c-trib
    Jan 30, 2017 @ 21:41
    David Peck
    0

    As for

    Also for it to work at all, you have to have the site actually running in debug mode or the custom tool can't find the site, which means you can't work on the code, create folders, files, etc.

    I'm afraid you've lost me. Running is debug is basically the same as not, when working in a dev environment. You wouldn't want to be creating .cs files against a live website... would you?

  • Craig100 846 posts 1719 karma points
    Jan 30, 2017 @ 22:03
    Craig100
    0

    Hi David.

    The example here: http://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder siting the models/builder.cs works fine as a test in my web project but only while the site is run (ctrl+F5) in debug. If it's not running or running without debug then there is an error saying "The custom tool UmbracoModelsBuilder failed". Which is why I thought I must have missed some step in the set up, as you can't be stopping and starting the site all the time to edit files, it's ridiculous.

    As for not creating models, then what's the point? The reason I'm going through this pain (for about the 4th time in a year) is to gain some work benefit, not to have to manually create models. But (as with UaaS deploy recently) all I'm getting is a serious waste of time (money) and patience.

    What I'm expecting is for models to be created automatically, either by VS or the site, ( I don't mind which) but then can be worked with intellisense, in VS. Unless there's a proper guide somewhere, which I don't believe there is, then I'll have to bodge something from what's available and hope that a week's effort down the line it doesn't all blow up in my face again. Umbraco can be so frustrating.

  • David Peck 527 posts 1333 karma points c-trib
    Jan 30, 2017 @ 22:32
    David Peck
    0

    I don't need to run it debug like you're suggesting. Perhaps that's because I'm running it in genuine IIS?

    You should only need to create properties that have object as their type. In my experience this as been 5% of properties as most are string, bool, IHtmlString or similar .NET type. 3rd party packages like nuPickers are setup correctly to set the return type of their own. Others aren't. I take it you saw in my example that this was a partial class and so I only need to put in to this the properties that I'm overridding?

    It took me a couple of days to get my head around the Visual Studio Custom Tool, but I have to say I think it's brilliant now. Sometimes it has it's quirks, but generally it speeds everything up.

    If you don't like it then maybe check-out Ditto. It won't create your models for you, which I realise is one of your goals, but it is a lot simpler to use.

  • Craig100 846 posts 1719 karma points
    Jan 30, 2017 @ 22:44
    Craig100
    0

    Thanks David,

    I'm running with VS as you would normally, no one has specified anything else.

    I wouldn't know what properties have "object" as their type. I just want to create documentTypes and have the models built as automatically as possible and be available in VS.

    I use Umbraco because I want to be spending my energies creatively, not waste them failing to set stuff up because of poor or no documentation. But it frequently gets me thinking if I might be better off with another CMS. Going down day long dead ends all the time is very draining, not to mention expensive.

    I think I realise now there's not going to be any documentation on this. It's been promised for over a year, looking back at various threads on the subject. I'll just muddle on I guess and mutter to myself.

  • David Peck 527 posts 1333 karma points c-trib
    Jan 30, 2017 @ 22:52
    David Peck
    0

    Maybe give up on the creation of the models in Visual Studio and got with the DLL mode.

    https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/80094-intellisense-with-modelsbuilder-in-visual-studio

  • Stephen 707 posts 1984 karma points core hq
    Apr 21, 2017 @ 15:49
    Stephen
    0

    Bit late to the party, but nevertheless...

    The bit about running "debug" means that the site the API talks to must be running in "debug" mode, ie web.config system.web/compilation/@debug is set to true - this is for safety reasons, so that the API does not remain open on live sites.

    So... for the VS extension to work, of course the site must be running (because we connect to it) and I understand that if you are editing the site at the same time, starting/stopping it can be annoying. No ideal solution here... I run my sites in IIS (with debug="true") so that I can work in Visual Studio and use the API when needed.

    Now about generating models... I am not sure to 100% understand you here. Are you talking about models for the values of specific properties? If so... we cannot generate these models as they really depend on the property value editor that is used in the back-office and on how it stores its data, internally. We do provide "models" for the most common editors (numeric, rich text... and with 7.6, most pickers, etc.) - do you have specific data type in mind?

    Hopefully this makes sense and will help with the frustration ;-)

  • Craig100 846 posts 1719 karma points
    Apr 21, 2017 @ 16:05
    Craig100
    0

    The final answer to pretty much all of my ModelsBuilder woes was to do the 4 to 7 Bridging Course AND this wonderful set of Umbraco TV tutorials: http://umbraco.tv/videos/umbraco-v7/implementor/working-with-umbraco-data/working-with-models-builder/

    I would strongly encourage anyone that has MB questions to watch the videos first :)

  • Jeff Subat 28 posts 159 karma points
    Apr 27, 2017 @ 18:21
    Jeff Subat
    0

    Craig, here's another option. I am happily using AppData mode with my Umbraco Cloud projects in Visual Studio. Here's what I did:

    1. Installed the Umbraco.ModelsBuilder Nuget package in my .Core project

    2. Added keys to the web.config in my .Web project as follows:

      <add key="Umbraco.ModelsBuilder.Enable" value="true" />
      <add key="Umbraco.ModelsBuilder.ModelsMode" value="AppData" />
      <add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/../MyProject.Core/Models/Generated" />
      <add key="Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory" value="true" />
      
    3. Started using ModelsBuilder per the standard procedure for AppData mode. That means I need to use the back office to generate models.

    Had I been able to figure out how to use API package with a separate .Core project (which I couldn't), I might have gone down that path. Now it seems to me that using AppData mode with this setup is simpler.

Please Sign in or register to post replies

Write your reply to:

Draft