.Net Core 和完整框架项目合二为一 [英] .Net Core and Full Framework projects in one solution

查看:29
本文介绍了.Net Core 和完整框架项目合二为一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含多个项目的解决方案.其中一个项目是 Main(放置通用代码和 API),其余项目是 Main 的扩展(Extension1、Extension2、Extension3)并使用第三方库.现在,我正在使解决方案兼容完整框架和 .Net Core 框架.

在我开始添加对 .Net Core 的支持之前,该解决方案已经有取决于目标框架的条件构建过程,所以我在条件构建方面还没有问题.

我遇到的问题是第三方库的一部分与 .Net Core 不兼容.这使得部分扩展与 .Net Core 不兼容.我想到的唯一选择是为完整框架和 .Net Core 框架提供单独的解决方案和代码库.但是我希望在这两种情况下都有相同的代码库,因为我的代码与这两个框架都非常兼容,否则支持起来会很痛苦.

对于这种情况,是否可以只有一种解决方案,并且能够为完整框架构建 (Main + (Extension1, Extension2, Extension3)) 项目,为 .Net Core Framework 构建 (Main + (Extension1, Extension2)) 项目?如果不是,我有什么选择?

先谢谢大家

解决方案

您想了解

顶部是 .NET Standard 的版本,左下方是框架的版本.使用此图表,您可以看到以下支持 .NET Standard 2.0:

  • .NET 核心 2.0
  • .NET 框架 4.6.1
  • 单声道 5.4等

这意味着任何以这些框架为目标的应用程序都可以访问 .NET Standard 2.0 中列出的 API.

在您的示例中,您可以在 .NET Standard 兼容库中拥有所有业务逻辑(无论它们是 Framework 还是 Core),并且有两个单独的 Main 项目(一个用于 Framework,一个用于 Core).

这可以通过三个单独的解决方案来完成:

  • 一个用于 .NET Standard 类库
  • 一个用于 .NET Framework Main(包括 .NET Standard 类库)
  • 一个用于 .NET Core Main(包括 .NET Standard 类库)

您还可以将 .NET Standard 类库构建为 NuGet 包(无论是否在外部托管它们),并将它们拉入您的两个(.NET Framework 和 .NET Core)主要解决方案中.

Say I have a solution with several projects included. One of projects is Main (where general code and APIs are placed) and the rest are kind of extensions (Extension1, Extension2, Extension3) for the Main and use third-party libraries. Now I'm making the solution compatible on both Full Framework and .Net Core Framework.

The solution had already had conditional building process depending on target framework before I started adding support for .Net Core, so I have no problems with conditional building yet.

The problem what I do have is that part of third-party libraries is not compatible with .Net Core yet. That makes a part of the extensions incompatible with .Net Core. The only option that comes to my mind is to have separate solutions and code bases for full framework and .Net Core Framework. BUT I would like to have same code base in both cases because my code is pretty compatible with both frameworks and otherwise it would be such a pain in the neck to support.

Is it possible to have only one solution for that case and be able to build (Main + (Extension1, Extension2, Extension3)) projects for full framework and (Main + (Extension1, Extension2)) for .Net Core Framework? If it's not, what options do I have?

Thank you all in advance

解决方案

You want to be looking into .NET Standard - I'd also take a look at the videos put out by Immo Landwerth about it.

The tl;dr is that .NET Standard lists the APIs and methods which you can expect a .NET application (Framework, Core, WPF, Xamarin, etc.) to have access to. Higher version numbers of the standard include more APIs but reduce the number of frameworks you can use (Framework, Core, WPF, Xamarin, etc.).

Here's a visual of how .NET Standard is adopted and supported by the different frameworks.

Along the top are the versions of .NET Standard, and down the left are the versions of the frameworks. Using this chart, you can see that .NET Standard 2.0 is supported by:

  • .NET Core 2.0
  • .NET Framework 4.6.1
  • Mono 5.4 etc.

This means that any application which targets any of those frameworks will have access to the APIs listed in .NET Standard 2.0.

In your example, you could have all of your business logic in .NET Standard compatible libraries (regardless of whether they are Framework or Core) and have two separate Main projects (one for Framework and one for Core).

This could be done with three separate solutions:

  • One for your .NET Standard class libraries
  • One for your .NET Framework Main (which includes the .NET Standard class libraries)
  • One for your .NET Core Main (which includes the .NET Standard class libraries)

You could also build the .NET Standard class libraries as a NuGet package (with or without hosting them externally) and pull them into your two (.NET Framework and .NET Core) Main solutions.

这篇关于.Net Core 和完整框架项目合二为一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆