NET Standard与Net Core App:创建.NET Core Project时(使用控制台或类库) [英] NET Standard vs Net Core App: when creating .NET Core Project (using console or class library)

查看:197
本文介绍了NET Standard与Net Core App:创建.NET Core Project时(使用控制台或类库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的项目开发为跨平台的。我以这种方式创建了几个类库:

I am trying to develop my projects to be cross platform. I have created several class libraries in this way:

但是,当我使用Entity Framework搭建数据库时,所需的nuget包却没有'

But, when I was using Entity Framework to scaffold my DB, the nuget packages needed didn't install except when used in Console application.

这里是区别,控制台应用程序引用了.NET Core:

Here is the difference, the console app references the .NET Core:

并且类库引用NET标准:

And the Class library references NET Standard:

那么为什么它们都在.NET Core下却引用不同的库?它们都是跨平台的还是仅使用.NET Core的控制台?
并且在这种情况下我应该避免使用类库吗?

So why they are both under .NET Core but referencing different libraries? Are both of them Cross Platform or only the console which is using .NET Core? And should I avoid using Class libraries in this case?

推荐答案

为什么它们都在下面.NET Core但引用了不同的库?

现在为网络标准库。这就是为什么在创建类库时默认的是net标准版本而不是Net Core。您可以手动更改它,但不建议您参阅有关引入.NET标准库

"So why they are both under .NET Core but referencing different libraries?"
The recommended NET version to create libraries for is now Net Standard Library. That is why the default when you create a class library is the net standard version instead of Net Core. You could manually change that but is not recommended see also this blog post about Introducing .NET Standard Library.

它们都是跨平台的还是仅使用.NET Core的控制台? / strong>

是的,它们都是跨平台的。

Are both of them Cross Platform or only the console which is using .NET Core?
Yes, they are both cross platform.

在这种情况下,我应该避免使用类库吗?

不,一定可以每次使用Class Libraries。最初,这并不是Microsoft的初衷,但后来他们改变了主意,因此,并非所有软件包都与.net标准兼容,这就是为什么您不能使用net标准版本来创建脚手架项目的原因,因为 Microsoft。 EntityFrameworkCore.Tools目前仅与Net core兼容,但很快可能与DotNet Standard兼容。

And should I avoid using Class libraries in this case?
No, by all means use Class Libraries every time is possible. This was not the original intent of Microsoft in the beginning but they change their mind later, so not all packages are yet compatible with .net standard that's is why you can not use a the net standard version to have a scaffold project because "Microsoft.EntityFrameworkCore.Tools" at the moment is only compatible with Net core, but it will probably be compatible with DotNet Standard soon

正如我所说,如果您真的想保留支架选项,则可以使用类库项目,并在project.json中手动更改.net版本,然后兼容即可切换回.net标准。根据您希望如何保持分隔的其他项目(例如服务或数据层)可以是具有dotnet标准的类库,并且它们将能够正常工作。

As I said if you really want to keep the scaffold option, then you can use a class library project and change manually in the project.json the .net version, then once is compatible you can switch back to .net standard. Your other projects such as a service or data layer depending how you want to keep the separation can be a class library with dotnet standard and they will be able to work correctly.

或者,您可以使用原始解决方案中的控制台应用程序(.net核心)appart,然后使用.net标准将其复制并粘贴到您的真实类库中。 (这就是我们目前在项目中所做的事情)

Or you could have a console application (.net core) appart from your original solution and copy and paste into your real class library using .net standard. (This is what we are currently doing in project)

这篇关于NET Standard与Net Core App:创建.NET Core Project时(使用控制台或类库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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