49

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?

1
  • A very similar Q&A, differing mainly in the versions, but still after the huge change in ASP.NET Core 3.0: stackoverflow.com/q/58175530/2157640 Commented Dec 16, 2022 at 23:23

1 Answer 1

98

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Just a side-note. Of course this does not work for netstandard targets.
Also, does not work for MAUI. github.com/dotnet/maui/issues/17725

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.