NET Standard vs Net Core App: when creating .NET Core Project (using console or class library)

那年仲夏 提交于 2019-12-30 06:06:44

问题


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

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

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

And the Class library references NET Standard:

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?


回答1:


"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.

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

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

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.

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)



来源:https://stackoverflow.com/questions/40004339/net-standard-vs-net-core-app-when-creating-net-core-project-using-console-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!