Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Microsoft.AspNetCore.All package in netstandard

At the moment I'm porting an asp web api to .Net Core.

The api uses a Class library which provides some implementations of the ActionFilterAttribute class.

So I have to port this class library as well. When I tried to add the nuget package Microsoft.AspNetCore.All to the class library I recived this error:

Package Microsoft.AspNetCore.All 2.0.0 is not compatible with netstandard2.0

When I change the target framework to netcoreapp2.0, I'm able to install the package, but of course I need an entry point for this target type.

How can I create a netcore class library which can use the Microsoft.AspNetCore.All package

Greetings

like image 999
Ced Avatar asked Sep 11 '17 08:09

Ced


People also ask

What is the difference between Microsoft ASP.NET Core App and Microsoft NET Core app?

NET Core vs ASP.NET Core. . NET Core is a runtime to execute applications build on it. ASP.NET Core is a web framework to build web apps, IoT apps, and mobile backends on the top of .

Is .NET standard compatible with .NET 6?

2 Answers. According to this document, . NET 6 supports . NET Standard 2.1.

Can I use .NET standard in .NET Core?

Because . NET Core 2.0 implements . NET Standard 2.0, it also has the compatibility mode for referencing . NET Framework libraries.

Is .NET 6 compatible with .NET standard 2?

NET Standard 2.0 at all. So you can take a . NET Standard 2.0 library and reference it in . NET 6, and that'll work fine.


2 Answers

You can't (well technically you could via NuGet Fallback, but you shouldn't as it may affect your portability) and you shouldn't.

The .All package is a convenience meta-package, so you don't need to reference a dozen or other assemblies for even the simplest ASP.NET Core Project.

It's targeting .NET Core for a reason, so you can't use it in .NET Standard.

When you publish your application, the unused packages will be stripped off. When doing a class library you don't want dependency on everything but only the packages which are required by your project.

like image 176
Tseng Avatar answered Nov 16 '22 01:11

Tseng


The metapackage Microsoft.AspNetCore.All is only available for .NETCoreApp. This is by design since its explictly targeted as a convenience package for web applications running on .NET Core. In order to work its magic at publishing time (stripping of unused dependencies), it requires the .NET Core runtime store which is only available for .NET Core itself.

All other projects, including library projects running on .NET Standard but also including all projects that run on the full .NET Framework, should use individual package references instead.

So instead of referencing Microsoft.AspNetCore.All, you would be referencing e.g. Microsoft.AspNetCore, or Microsoft.AspNetCore.Mvc to get your ActionFilterAttribute.

like image 40
poke Avatar answered Nov 16 '22 00:11

poke