At a guess you are probably getting the "error" as a false positive because you are using PureLive or DLL model for models builder (PureLive is the default). The error shows because the models don't exist untill run time and so VS thinks you are referencing things that don't exist (which is technically correct as at this point they dont), as a result you also can't get an intellisense .
Makes sense what you're saying. Yea the intellisense is the part i was wondering about. So the Models don't exist til runtime huh?
I don't know the answer to your question about the PureLive or DLL. I haven't being using models builder on my other umbraco 7 projects (I don't think). When I spun up the new template in umbraco 8 it defaulted to this strongly typed PublishedModels.
If you are spinning up a clean site then you are most likely using PureLive. You can check this by looking in the AppSettings in WebConfig. There should be a key called Models Builder Mode (or something similar) and it will probably read PureLive.
The template is strongly typed, which is the good thing, as I say, it's just the VS behaviour that makes you question it :-)
There are other modes, and I do recommend reading up on them to figure out what mode will work best for you. PureLive and DLL allow models to be created on the fly (runtime), where as the others generally lead you to creating them at compile time :-)
So without intellisense what's the benefit of ModelsBuilder? Just that I can use @Model.attributeName instead of @Model.GetPropertyValue("attributeName")?
I read up on Models Builder. I was sadly behind. I think I'd like to give DLL a go. I've "created" some DocTypes. Do you know if switch from PureLive to DLL in web.config if changes to those DocTypes will be picked up, or do I need to start over on those DocTypes?
The advantage of Models builder is strongly typed models, and more so it's become a much better advantage now we have PropertyValueConverters as well.
So, for example, you can do @Model.BannerImage.Url (although this is bad code for a different reason as BannerImage could be null even if you checked it had a value due to how the PropertyValueConverters work).
Also, with Models builder models you can still do .GetPropertyValue because they all expose IPublishedContent which that extension method words off of.
Strongly typed models, make your code, in theory, more readable which is nicer from a maintenance point of view.
When you switch to Dll mode, in the back office you can go to the Models Builder dashboard in the developers section and tell your back office to regenerate the Dll. This will pick up changes you've made to doc types so you don't have to start over with any doc type changes :-)
Dll mode will generate a dll in your bin directory called Umbraco.Web.PublishedModels which contains all of your compiled models.
Now, I think you might still get the Intelli-sense issue you are currently getting unless you explicitly reference the dll in your project, but the issue you may get with this is that if you don't have that dll (for example if you do a clean of your solution) you may end up unable to run your project depending on if you have to reference Models in .cs files due to visual studio being unable to compile. Just as a warning :-)
When you make the switch you "may" also get a temporary issue where 2 instances of models is found by the website but you can resolve this by doing a restart of the site I believe :-)
greatttt... "Boot failed: Umbraco cannot run. See Umbraco's log file for more details." after switching to Dll I did the settings > Generate Models and mine didn't restart, so I stopped it in VS and tried to start again, and got this error. Sorry to bug ya'll but now i'm hosed.
yes to log file errors. I've tried a few different things trying to get back to good. Switching back to PureLive isn't copacetic either.
Got the dual class reference error that @Nik mentioned. Now i'm back to Dll mode, but my project won't build says it's missing Model files that are there (but they show in VS with yellow triangle).
Update: Excluded the missing models and got it to build in Dll mode. Generating models does not cause a restart automatically. I'm unsure how to proceed here.
DocType Does Not Exist in PublishedModels
In VS2017 i'm getting the error
relevant code
This is the case on all of my strongly typed views. What do I need to do to correct this?
Hi bh,
What models builder mode are you using?
At a guess you are probably getting the "error" as a false positive because you are using PureLive or DLL model for models builder (PureLive is the default). The error shows because the models don't exist untill run time and so VS thinks you are referencing things that don't exist (which is technically correct as at this point they dont), as a result you also can't get an intellisense .
Nik
Thanks @Nik
Makes sense what you're saying. Yea the intellisense is the part i was wondering about. So the Models don't exist til runtime huh?
I don't know the answer to your question about the PureLive or DLL. I haven't being using models builder on my other umbraco 7 projects (I don't think). When I spun up the new template in umbraco 8 it defaulted to this strongly typed PublishedModels.
No problem :-)
If you are spinning up a clean site then you are most likely using PureLive. You can check this by looking in the AppSettings in WebConfig. There should be a key called Models Builder Mode (or something similar) and it will probably read PureLive.
The template is strongly typed, which is the good thing, as I say, it's just the VS behaviour that makes you question it :-)
There are other modes, and I do recommend reading up on them to figure out what mode will work best for you. PureLive and DLL allow models to be created on the fly (runtime), where as the others generally lead you to creating them at compile time :-)
Nik
Thanks again @Nik.
Yup. PureLive according to web.config
So without intellisense what's the benefit of ModelsBuilder? Just that I can use @Model.attributeName instead of @Model.GetPropertyValue("attributeName")?
I read up on Models Builder. I was sadly behind. I think I'd like to give DLL a go. I've "created" some DocTypes. Do you know if switch from PureLive to DLL in web.config if changes to those DocTypes will be picked up, or do I need to start over on those DocTypes?
Hi bh
Just switch to DLL, and go to into the backend and build the Models (Developer section on v7's, Settings on v8's), then you can use Intellisense.
It won't affect what you have created sofar.
The advantage of Models builder is strongly typed models, and more so it's become a much better advantage now we have PropertyValueConverters as well.
So, for example, you can do
@Model.BannerImage.Url
(although this is bad code for a different reason as BannerImage could be null even if you checked it had a value due to how the PropertyValueConverters work).Also, with Models builder models you can still do
.GetPropertyValue
because they all expose IPublishedContent which that extension method words off of.Strongly typed models, make your code, in theory, more readable which is nicer from a maintenance point of view.
When you switch to Dll mode, in the back office you can go to the Models Builder dashboard in the developers section and tell your back office to regenerate the Dll. This will pick up changes you've made to doc types so you don't have to start over with any doc type changes :-)
Dll mode will generate a dll in your bin directory called
Umbraco.Web.PublishedModels
which contains all of your compiled models.Now, I think you might still get the Intelli-sense issue you are currently getting unless you explicitly reference the dll in your project, but the issue you may get with this is that if you don't have that dll (for example if you do a clean of your solution) you may end up unable to run your project depending on if you have to reference Models in .cs files due to visual studio being unable to compile. Just as a warning :-)
When you make the switch you "may" also get a temporary issue where 2 instances of models is found by the website but you can resolve this by doing a restart of the site I believe :-)
greatttt... "Boot failed: Umbraco cannot run. See Umbraco's log file for more details." after switching to Dll I did the settings > Generate Models and mine didn't restart, so I stopped it in VS and tried to start again, and got this error. Sorry to bug ya'll but now i'm hosed.
Switched back to PureLive and i'm up and running again.
Did you get any errors in the log?
yes to log file errors. I've tried a few different things trying to get back to good. Switching back to PureLive isn't copacetic either. Got the dual class reference error that @Nik mentioned. Now i'm back to Dll mode, but my project won't build says it's missing Model files that are there (but they show in VS with yellow triangle).
Here's the log file: https://www.dropbox.com/s/0uuowj7ffqnzvaq/UmbracoTraceLog.HUDSONB-LT.20190312.json?dl=0
Update: Excluded the missing models and got it to build in Dll mode. Generating models does not cause a restart automatically. I'm unsure how to proceed here.
@bh I have had the identical issues. Did you find a way of solving this?
@DChad The how has changed since this post last March.
In Visual Studio:
If you get stuck there's documentation here: https://www.zpqrtbnk.net/posts/models-builder-extension/
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.