一个解决方案中的.Net Core和Full Framework项目 [英] .Net Core and Full Framework projects in one solution

查看:120
本文介绍了一个解决方案中的.Net Core和Full Framework项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个包含多个项目的解决方案。其中一个项目是Main(放置通用代码和API),其余项目是Main的一种扩展(Extension1,Extension2,Extension3),并使用第三方库。现在,我正在使该解决方案在Full Framework和.Net Core Framework上都兼容。



在开始添加支持之前,该解决方案已经根据目标框架进行了有条件的构建过程。对于.Net Core,所以我对条件构建没有任何疑问。



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



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



谢谢大家

解决方案

您想研究



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




  • .NET Core 2.0

  • .NET Framework 4.6.1

  • Mono 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和Full Framework项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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