简体   繁体   English

如何在一个项目中将第三方代码包含在单独的版本中

[英]How to include 3rd party code in separate versions in one project

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的,但是我想解决此问题的方法将是可以应用于拥有多个运行不同版本框架的网站的任何人。

Right now I have 3 separate websites running Sitecore as the framework and CMS for the sites. 现在,我有3个单独的网站,分别运行Sitecore作为框架和网站的CMS。 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. 一个网站从Sitecore 6.5运行代码,另一个网站在7.0上,另一个网站在7.0上,但很快就会达到7.2。

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. 我想建立一个单独的C#项目,以包括处理Sitecore特定的逻辑和类。 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版本中。

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之间有大量共享功能,我希望能够在一个地方编写与版本无关的代码。

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. 我不在乎它是否需要为我需要编译的每套Sitecore DLL建立3个单独的DLL,只要我可以保留一个基本源即可。 Is this sort of thing possible? 这种事情可能吗?

How I would handle it: 我将如何处理:

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 ). 许多简单的.NET代码可能可以通用共享,但是,如果您使用的是不同版本的SC,则很可能会处理不推荐使用的功能,API更改等。我可以想到的一个示例是UIFilterHelpers.ParseDatasourceString (在7.2中已弃用,而SearchStringModel.ParseDatasourceString )。 There are a log of ways to approach this, but for example: 有很多方法可以解决此问题,例如:

Inline Versions 内联版本

#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: 另一种方法是使用partial类并定义特定于版本的实现(然后仅将它们包含在正确的项目中。也许您具有:

  • Common.sln Common.sln
    • Common.SC65.csproj Common.SC65.csproj
      • MyClass.cs [shared] MyClass.cs [共享的]
      • MyClass.SC65.cs MyClass.SC65.cs
    • Common.SC7.csproj Common.SC7.csproj
      • MyClass.cs [shared] MyClass.cs [共享的]
      • MyClass.SC7.cs MyClass.SC7.cs
    • Common.SC72.csproj Common.SC72.csproj
      • MyClass.cs [shared] MyClass.cs [共享的]
      • MyClass.SC72.cs MyClass.SC72.cs

In the above, MyClass.cs resides in the root and is included in every project. 在上面, MyClass.cs驻留在根目录中,并且包含在每个项目中。 However, the .SC#.cs files are only included in the project targeting the specific sitecore version. 但是, .SC#.cs文件仅包含在针对特定站点核心版本的项目中。

This pattern is used a lot by libraries that target different .NET platforms or various configurations. 针对不同的.NET平台或各种配置的库经常使用此模式。 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). 要使用MVC示例,您需要拥有MyProject.csprojMyProject.MVC3.csprojMyProject.MVC4.csprojMyProject.MVC5.csproj (每个都有不同的引用以及可能的框架版本)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用ClickOnce部署多个版本的第三方DLL? - How to deploy multiple versions of a 3rd party DLL with ClickOnce? 试图了解如何在IronPython中包含第三方模块 - Trying to understand how to include 3rd party modules in IronPython 如何将第三方dll资源文件包含到安装包中 - How to include 3rd party dll resources file into install package ASP.NET Core:Docker 还原/构建未能包含项目中的第 3 方程序集 - ASP.NET Core: Docker restore/build failed to include the 3rd party assembly from project 如何从支持 linux/mac os 的第 3 方代码为我的 c# 项目制作 dll? - How can i make a dll for my c# project from a linux/mac os supported 3rd party code? 需要一种方法来引用同一个第 3 方 DLL 的 2 个不同版本 - Need a way to reference 2 different versions of the same 3rd party DLL Nuget / MSBuild:为多个第 3 方 DLL 版本构建 - Nuget / MSBuild : Build for multiple 3rd Party DLL versions 在Visual Studio项目中使用3rd party exe,然后将其包装为一个用于在线安装程序 - Using 3rd party exe in visual studio project and then wrapping it into one for online installer 我的项目引用了另一个引用第三方程序集的项目。 如何设置此第三方组件的装配路径? - My project references another project which references a 3rd party assembly. How do I set the assembly path for this 3rd party assembly? 如何禁用第三方事件循环 - How to disable 3rd party event loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM