简体   繁体   中英

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:

  • WebApplicationOptions
  • HttpContext

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM