Rast
Rast

Reputation: 2621

How to reference ASP.NET Core 6 types in .NET 6 library?

I am working on internal libraries for my organization. I need to reference certain types that normally "belong" to web apps, eg. to provide some extensions:

If I use <Project Sdk="Microsoft.NET.Sdk">, i don't have references to these types and can't find any nuget package which contains them. If i use <Project Sdk="Microsoft.NET.Sdk.Web">, i can't build my class library because it is treated as application and has to specify entry point.

So, my question in general: what is the right way to write libraries for ASP.NET Core 6?

Back in core 2.x days there were packages for everything, like Microsoft.AspNetCore.Http.Abstractions. They are all stuck at version 2.2.0 and i assume they're not usable now?

Upvotes: 48

Views: 32703

Answers (1)

Martin Costello
Martin Costello

Reputation: 10862

You need to add a FrameworkReference to your project file instead of a PackageReference as described here.

<ItemGroup>
  <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

Right-click your project in the Solution Explorer and select "Edit Project File" to open the file and look for the <ItemGroup> section, creating a new one if it does not exist.

Upvotes: 96

Related Questions