Sitecore Glass.Mapper.Sc 与 Glass.Mapper.Sc.Core

Sitecore Glass.Mapper.Sc vs Glass.Mapper.Sc.Core

大家好 Sitecoryians,

我正在将 Sitecore 7.1 rev140130 webforms 上的网站升级到 Sitecore 8.2rev160729 MVC-5 / Webforms hybrid。我要求保留旧内容 运行。因为这只是后端的升级。但计划开始在 MVC 中开发所有新组件等。随着内容页面的变化,我将逐步淘汰旧的 Web 表单。这个要求是业务推给我的。

旧站点使用 Glass Mapper 从 sitecore 生成和映射内容。通过 TDS 中的 t4 脚本使用旧 Glass.Mapper.Sc.CasteWindsor v3.2.1.21。

我查看了 Glass 主页。 Where is 声明 Glass.Mapper.Sc 是您现在所需要的。但是那里有相互矛盾的教程,说明您需要安装 MVC-4 或 MVC-5。我想我现在会忽略它们并坚持使用 Glass 建议的安装。

问题是旧的模型属性被标记为类似 [SitecoreId] & [SitecoreInfo(SitecoreInfoType.Language)]

Glass.Mapper.Sc 库中似乎没有。我可以在可用的 nugets 包中找到这些属性的唯一参考。是Glass.Mapper.Sc.核心包。

我试图在模型项目中安装那个包。只是为了看看这个:

Start package installation to project [project].Logic.Models Installation failed. Rolling back... Error: Unable to resolve dependencies. 'Glass.Mapper.Sc.Core 4.2.1.189' is not > compatible with 'Glass.Mapper.Sc 4.3.1.194 constraint: Glass.Mapper.Sc.Core (≥ > 4.3.1.194)'. Installation finished.

我觉得如果我将 Glass.Mapper.Sc 降级以便安装核心库,我可能会犯错误。以后我可能搬起石头砸自己的脚。因为我仍然必须安装 WFFM 和社交连接模块被替换为内部 sc8 社交组件..

我的理解是新的 Glass.Mapper.Sc 包应该能满足我的所有需求。

那么我应该降级并尝试将旧版本与核心库一起使用吗?

或者我应该重构模型以使用新的属性系统。那可能是什么?

(请记住,项目中大约有 50 多个模型。所以这不是我想要做的事情..)

Glass Mapper 在版本 4 中发生了显着变化,最大的变化是移除和依赖 Castle Windsor。 release blog post.

中列出了更改列表

Nuget package/installer 也已更改,因此现在只有一个 Nuget 包,而不是之前必须安装的几个。为了支持这一点,Nuget 安装程序检查是否存在 Sitecore.Kernel.dllSystem.Web.Mvc:

To make things simpler V4 uses a Powershell script to decided which references to add to your project, it checks both the Sitecore.Kernel version and the System.Web.Mvc version and then installs the appropriate Glass.Mapper.Sc and Glass.Mapper.Sc.Mvc assembly.

我的建议是删除旧的 V3 程序集和 Nuget 引用,确保在您的项目中正确引用了上述 2 个 DLL,然后再次将 Glass V4 Nuget 安装到这些项目。

SitecoreId and SitecoreInfo 属性仍在 Glass.Mapper.Sc 库中,核心库已 removed/refactored。我不认为这个命名空间自 V3 以来发生了变化,但请确保您使用的是 GlassV3Header.tt 文件并且该文件中的 using Glass.Mapper.Sc.Configuration.Attributes 命名空间是正确的。

https://github.com/HedgehogDevelopment/tds-codegen/blob/master/Sitecore.Master/Code%20Generation%20Templates/GlassV3Header.tt#L32