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?
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!
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".
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.
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
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.
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.
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.
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.
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.
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
ormodels.generated.cs
- what is the difference or purpose of each?Thanks, Simon
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!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 :
Otherwise it doesn't work and you just get an "object".
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
Until you mentioned it I didn't actually know about the appsettings so they were just OOTB.
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:
Source: http://www.zpqrtbnk.net/posts/purelive-models-introduction
So I am actually referencing
models.generated.cs
in my solution.Cheers, Simon
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:
I completely understand why this happens and is simply fixed by setting the Build Action to
None
for that file.Hello,
Maybe this topic can also help: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/75079-74-models-builder
Jeroen
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 :
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?
I seem to get this intermittently in v7.4.0 also and have to alternate by including either
all.generated.cs
ormodels.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
I can only make it to see my generated classes if I include
all.generated.cs
to the project withBuild 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" />
inweb.config
? Neither seem to work, no dll is generated in bin folder.Thanks!
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:
However things may have changed since the version I am using it on.
Simon
Details on another way of using it: https://pynej.blogspot.com/2016/10/guide-to-using-strong-typed.html
is working on a reply...