Copied to clipboard

Flag this post as spam?

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


  • Jeff Subat 28 posts 159 karma points
    Feb 02, 2017 @ 21:53
    Jeff Subat
    0

    ModelsBuilder generate models to Umbraco Cloud .Core project

    In order to enable good testing practices, I'd like to generate ModelsBuilder models in the separate .Core class-library project that is set up by the Umbraco Cloud UaaS.cmd utility.

    Having read a bit of the ModelsBuilder documentation on GitHub, I got the impression that the cleanest way to do this would be to use "Api models" via the Visual Studio extension.

    I followed the instructions at Builder Modes - API Models and Install and Configure - Models Builder API. I created the empty .cs file in the .Core class library I mentioned above, and set its Custom Tool value to UmbracoModelsBuilder. When I run the tool, though, I simply get the message "... One or more errors occurred."

    I believe the source of my problem is a missing reference or a missing application setting.

    In the documentation, it says "... the Umbraco.ModelsBuilder.Api NuGet package needs to be installed," but it doesn't say where it needs to be installed. It looks to me like it's already in the .Web project (though I can't imagine that matters). Out of desperation, I even installed it in my .Core class library. No luck.

    The documentation also says "... the following application setting needs to be configured: Umbraco.ModelsBuilder.EnableApi can be true or false (default) and controls whether the models builder provides the API." Again, though, it doesn't say where this setting is placed. I set it in the web.config of my .Web project but, as with the .Api package, I'm not sure how it could matter that it's in the .Web project.

    So, after that long-winded explanation, does anyone have a recommended setup for generating ModelsBuilder models into a separate class library in Visual Studio? Though I prefer it, I don't have to use the Api Models and Visual Studio extension.

  • Dave Woestenborghs 3340 posts 11251 karma points MVP 6x admin c-trib
    Feb 04, 2017 @ 12:18
    Dave Woestenborghs
    0

    Hi Jeff,

    Did you configure the VS extension with the url, username and password in Visual Studio. That is needed to get it to work.

    I explain that in this article : http://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/

    You can skip to the part API models.

    Dave

  • Jeff Subat 28 posts 159 karma points
    Feb 04, 2017 @ 17:12
    Jeff Subat
    0

    Thanks, Dave. I tried again, making sure I wan't missing anything from your article, and still no luck.

    Have you been able to get the custom tool to generate models in a separate class library before? In your article's screenshots, it looks like you were generating the models in the Umbraco web app.

  • Dirk De Grave 4538 posts 6009 karma points MVP 3x admin c-trib
    Feb 04, 2017 @ 13:11
    Dirk De Grave
    100

    If you want ModelsBuilder to generate your models in .Core project of the UaaS cloud solution, use

    Umbraco.ModelsBuilder.ModelsDirectory

    and

    Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory

    Umbraco.ModelsBuilder.ModelsDirectory will be something along the lines of ../../project.Core/Models/ (relative to the .Web project root folder)

    and Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory should be set to true

  • Jeff Subat 28 posts 159 karma points
    Feb 04, 2017 @ 17:31
    Jeff Subat
    0

    Thanks, Dirk, that works. :)

    One refinement to your instructions: the ModelsDirectory value only worked if I used the full path (C:\Users\myUserName\Documents\etc\etc\etc).

    Before I found the documentation on the Api Models approach, I had considered using this method. My concern was, and is, hard-coding into my web.config a path that refers to the file structure on my developer PC.

    Do you normally get around this issue by doing a web.config transform?

    Thanks, again, for the advice!

  • Dirk De Grave 4538 posts 6009 karma points MVP 3x admin c-trib
    Feb 04, 2017 @ 17:53
    Dirk De Grave
    0

    Rather strange you'd to specify full path, won't work in UaaS environment cause you don't know paths.

    On the other hand, you don't need to generate models on the live site, right, only on local dev, so you're covered I guess. I'm not sure if you can do web.config transforms (except for the ones Umbraco UaaS takes care of...), and if it were possible, you'd remove the settings on any non local dev environment.

    Have fun building your website.

    --Dirk

  • Jeff Subat 28 posts 159 karma points
    Feb 04, 2017 @ 18:02
    Jeff Subat
    0

    Thanks, Dirk. Yes, I tried something like "..\MyApp.Core\MyModels" and when I went into the backoffice, I received a message that the server couldn't find "C:\Users\MyUser\MyApp.Core\Models" (or something to that effect). The invalid concatenation clued me in that I needed the full path.

    Here's documentation on web.config transforms for UC: https://our.umbraco.org/documentation/Umbraco-Cloud/Set-Up/Config-Transforms/

    Based on that documentation, I'm kind of assuming I can do any transform I like. I am also considering changing the ModelsMode to PureLive in a transform, since my client has administrative access and I don't want them generating models. But, that's a topic for a different post!

  • Kenneth Solberg 226 posts 417 karma points
    Feb 16, 2017 @ 09:10
    Kenneth Solberg
    1

    Make sure the relative path is correct. I had a Umbraco Cloud VS solution generated by UaaS.cmd and here its ONE level up, not two:

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="AppData" />
    <add key="Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory" value="true"/>
    <add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/../Something.Core/Models"/>
    <add key="Umbraco.ModelsBuilder.ModelsNamespace" value="Something.Core.Models"/>
    

    Not sure why, maybe NTFS permissions, but nothing was generated two levels up if my relative path was ~/../../

  • Jeff Subat 28 posts 159 karma points
    Feb 16, 2017 @ 15:07
    Jeff Subat
    0

    Perfect, that solved the issue. Thanks, Kenneth!

Please Sign in or register to post replies

Write your reply to:

Draft