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.
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.
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?
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.
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.
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!
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.
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
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.
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
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!
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
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!
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:
Not sure why, maybe NTFS permissions, but nothing was generated two levels up if my relative path was ~/../../
Perfect, that solved the issue. Thanks, Kenneth!
is working on a reply...