Umbraco-cms: V8: models builder generated models - this.Value<type>

Created on 27 Feb 2019  路  7Comments  路  Source: umbraco/Umbraco-CMS

Fresh install of Umbraco 8.0.0 configured to utilise separate models project fails to find property of this.Value<type> in generated models.

Reproduction

Fresh Install from UaaS.cmd

Add Umbraco.Web.PublishedContentModels project and configure web.config

Add Nuget for UmbracoCMS.Core and Umbraco.ModelsBuilder and reference System.Web in new project

Add references as appropriate to CORE and WEB

Bug summary

The generated models comprise calls to return values by type, these calls fail to compile with error regarding failure to find definition or extension method for Value

Specifics

Umbraco 8.0.0 downloaded from git repo via UaaS.cmd
UmbracoCms.Core (8.0.0) nuget
Umbraco.ModelsBuilder (8.0.1) nuget

Steps to reproduce

Fresh Install from UaaS.cmd

Add Umbraco.Web.PublishedContentModels project and configure web.config

<add key="Umbraco.ModelsBuilder.Enable" value="true" />
<add key="Umbraco.ModelsBuilder.ModelsMode" value="AppData" />
<add key="Umbraco.ModelsBuilder.ModelsDirectory" value="~/../Umbraco.Web.PublishedContentModels" />
add key="Umbraco.ModelsBuilder.AcceptUnsafeModelsDirectory" value="true" />

Add nuget packages UmbracoCms.Core (8.0.0) and Umbraco.ModelsBuilder (8.0.1), add reference to System.Web

Reference new project Umbraco.Web.PublishedContentModels in both core and web projects.

Build, navigate to CMS and publish the content models.

Refresh Umbraco.Web.PublishedContentModels project and include the cs files for File, Image, Folder, Member

Attempt to Build

Expected result

Compiled solution ready to run

Actual result

Failure to compile with errors in generated cs files in Umbraco.Web.PublishedContentModels, E.g.

Error CS1061 'File' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'File' could be found (are you missing a using directive or an assembly reference?) Umbraco.Web.PublishedContentModels C:sg-htdocsu8-joUmbraco.Web.PublishedContentModelsFile.generated.cs 53 Active

image

Most helpful comment

Same issue. Seems like the .Value and .Value extension methods used by ModelsBuilder are in the Umbraco.Web dll and so installing UmbracoCms.Core in the models project isn't sufficient.

Solved for now by manually copying the Umbraco.Web dll over to the other project and referencing it, but that's not ideal.

I can confirm this worked for me! I downloaded via nuget. There is a nuget package for it. UmbracoCms.Web

All 7 comments

fwiw: i was able to resolve this by updating my projects TargetFramework to .net v4.7.2 as that is what the umbraco8 dlls are compiled against :thumbsup:

Same issue. Seems like the .Value and .Value extension methods used by ModelsBuilder are in the Umbraco.Web dll and so installing UmbracoCms.Core in the models project isn't sufficient.

Solved for now by manually copying the Umbraco.Web dll over to the other project and referencing it, but that's not ideal.

I

fwiw: i was able to resolve this by updating my projects TargetFramework to .net v4.7.2 as that is what the umbraco8 dlls are compiled against 馃憤

I think that is a solution to a problem I'm not having.

I suspect that is because your model builder is targeted to the same project as the main project so once you made the target the correct framework then all was well and of the Umbraco.Web.dll (as referred to by mattbirch) was already present?

Same issue. Seems like the .Value and .Value extension methods used by ModelsBuilder are in the Umbraco.Web dll and so installing UmbracoCms.Core in the models project isn't sufficient.

Solved for now by manually copying the Umbraco.Web dll over to the other project and referencing it, but that's not ideal.

I can confirm this worked for me! I downloaded via nuget. There is a nuget package for it. UmbracoCms.Web

Solved for now by manually copying the Umbraco.Web dll over to the other project and referencing it, but that's not ideal.

How about Install-Package UmbracoCms.Web?

For you @steadygo - it's the same problem, you are missing the assembly reference to Umbraco.Web. It sounds like the problem for everyone is missing references / framework versions. With a new version things are done a bit differently than on v7 and one of the differences is the NEW NuGet package UmbracoCms.Web.

Give it a go, adding it worked for me with the config you mentioned above! 馃憤

Ah perfect, I should have searched Nuget! Thanks @nul800sebastiaan

UmbracoCms.Web

Absolutely true. Solved by doing Install-Package UmbracoCms.Web @ the Core Project

This is an excellent article https://anotherdevblog.com/2018/07/18/organize-an-umbraco-projects/ that suggests this workaround.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aochmann picture aochmann  路  3Comments

Matthew-Wise picture Matthew-Wise  路  4Comments

sofietoft picture sofietoft  路  3Comments

glombek picture glombek  路  4Comments

janvanhelvoort picture janvanhelvoort  路  4Comments