How to access Microsoft.AspNetCore.Http.HttpContext in Microsoft.NET.Sdk project

David 31 Reputation points
2023-05-12T13:54:48.6533333+00:00

In Microsoft.NET.Sdk.Web projects, we can directly access Microsoft.AspNetCore.Http.HttpContext.

How to access HttpContext in Microsoft.NET.Sdk projects (representing a class library)? We discuss the tried options in the following table.

Option Discussion
Microsoft.NET.Sdk.Web projects We can access HttpContext, but a static Main method suitable for an entry point must be defined. And it does not represent a class library.
Microsoft.AspNetCore.Http.Abstractions (2.2.0) nuget package This package has been deprecated as part of the .NET Package Deprecation effort – https://github.com/dotnet/announcements/issues/217
Microsoft.AspNetCore.App.Ref nuget package This package is an internal implementation of the .NET Core SDK and is not meant to be used as a normal PackageReference.
Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET Other
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-05-12T17:21:22.9866667+00:00

    starting with net6, you specify the sdk.

    <Project Sdk="Microsoft.NET.Sdk.Web">
      <PropertyGroup>
        <OutputType>Library</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
    </Project>
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.