问题描述
我已经得到了我的手一个有趣的问题,我不能完全弄清楚处理它的正确方法。这是特定于Sitecore的,但我想修复这个问题将是一个可以适用于任何人,有运行不同版本的框架多个网站。
I've got an interesting problem on my hands and I can't quite figure out the right way of handling it. This is specific to sitecore, but I would imagine the fix to the issue would be one that could be applied to anyone that has multiple websites running different versions of a framework.
现在我有运行Sitecore的作为框架和CMS的网站3个独立的网站。一个网站它运行code从Sitecore的6.5,另一个是7.0,另一个是7.0,但将7.2很快。
Right now I have 3 separate websites running Sitecore as the framework and CMS for the sites. One website it running code from Sitecore 6.5, another is on 7.0, and another is on 7.0 but will be 7.2 soon enough.
一个编程的核心原则是不要重复自己。我想成立一个单独的C#项目,包括Sitecore的特定逻辑和类的处理。这将主要包括这样做简单的功能,使我的生活更方便的检查很多各种各样的东西类工具。这些基础功能都包含在Sitecore的每个版本我使用。
One of the core principles of programming is do not repeat yourself. I want to set up a separate C# project to include handling of Sitecore specific logic and classes. It would mostly include utility like classes that do simple functions to make my life easier checking many kinds of things. These base features are included in each version of Sitecore I am using.
基本上有一吨的,尽管差异Sitecore的DLL文件共享功能,并且我希望能够写的版本无关code在一个地方。的
Basically there is a ton of shared functionality between the Sitecore DLLs despite the differences, and I want to be able to write version agnostic code in one place.
如果它需要打造出为每套Sitecore的的DLL我需要编译的,只要3个独立的DLL我可以保持一个基本来源我不在乎。是这样的事情可能吗?
I don't care if it needs to build out 3 separate DLLs for each set of Sitecore DLLs I need to compile with, as long as I can keep one base source. Is this sort of thing possible?
推荐答案
我将如何处理它:
设置一个独立的项目,并使用配置/符号。很多简单的.NET code的大概可以普遍接受的,但是给你与不同版本的SC的工作,你最有可能对付德precated功能,API的变化,等等。一个例子,我可以想不到的是 UIFilterHelpers.ParseDatasourceString
(这是有利于 SearchStringModel.ParseDatasourceString
在7.2 pcated德$ p $)。有一个日志的方式来处理这一点,但例如:
Setup an independent project and make use of configurations/symbols. A lot of the simple .NET code can probably be universally shared, however give you're working with different versions of SC you would most likely deal with deprecated functionality, API changes, etc. One example I can think of is UIFilterHelpers.ParseDatasourceString
(which is deprecated in 7.2 in favor of SearchStringModel.ParseDatasourceString
). There are a log of ways to approach this, but for example:
#if SC7
IEnumerable<SearchStringModel> searchStringModel = UIFilterHelpers.ParseDatasourceString(Attributes["sc_datasource"]);
#else //SC72
IEnumerable<SearchStringModel> searchStringModel = SearchStringModel.ParseDatasourceString(Attributes["sc_datasource"]);
#endif
另一种方法是使用部分
类,定义特定版本的实现(则只包括那些在正确的项目也许你有:
Another approach is to use partial
classes and define version-specific implementations (then only include those in the correct project. Maybe you have:
- Common.sln
- Common.SC65.csproj
- MyClass.cs [分享]
- MyClass.SC65.cs
- MyClass.cs [分享]
- MyClass.SC7.cs
- MyClass.cs [分享]
- MyClass.SC72.cs
在上面,
MyClass.cs
驻留在根,包括在每一个项目。但是,.SC#的.cs
文件只包括在项目针对特定Sitecore的版本。In the above,
MyClass.cs
resides in the root and is included in every project. However, the.SC#.cs
files are only included in the project targeting the specific sitecore version.此模式是由针对不同的.NET平台和各种配置库中使用了很多。要使用MVC例如,你必须
MyProject.csproj
,MyProject.MVC3.csproj
,MyProject.MVC4.csproj
,MyProject.MVC5.csproj
(每个不同的引用和可能的框架版本)。This pattern is used a lot by libraries that target different .NET platforms or various configurations. To use an MVC example, you'd have
MyProject.csproj
,MyProject.MVC3.csproj
,MyProject.MVC4.csproj
,MyProject.MVC5.csproj
(each with different references and possibly framework versions).这篇关于如何在包括不同版本的第三方code在一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- Common.SC65.csproj