26

I have a .NET 7 Blazor helper library which has been referencing HttpContext from the Microsoft.AspNetCore.Http.Abstractions (2.2.0) nuget. However, this nuget is now flagged as deprecated by Microsoft, thus the Visual Studio Nuget manager shows me warnings for this package reference.

But my .Net7 Blazor app is using Microsoft.AspNetCore.Components.Web (7.0.5) and the root razor page _Host.cshtml exposes the HttpContext property, which I need to pass to a helper method in the above mentioned project.

What am I missing here? If I Browse my way to the HttpContext definition from _Host.cshtml, Visual Studio claims it's declared in Microsoft.AspNetCore.Http.Abstractions (7.0.0.0), which is nowhere to be found?

I also have similar issues with other, related packages. What's the correct way to reference these packages, without warnings? Or what other packages am I to use?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Ola Berntsson
  • 647
  • 1
  • 6
  • 12
  • 3
    Somebody else has just asked this exact same question! https://stackoverflow.com/questions/76173780/what-replaces-microsoft-aspnetcore-http-abstractions-when-migrating-to-net-7 which was closed as a duplicate! – phuzi May 04 '23 at 13:57
  • 3
    Check out the suggested duplicates. In short - remove the link to the nuget and add `FrameworkReference` element. Also check out [this part of docs](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-7.0&tabs=visual-studio#support-both-hosting-models) – Guru Stron May 04 '23 at 14:00
  • 2
    Thank you, unfortunately the `FrameworkReference` to **Microsoft.AspNetCore.App** prevents the library from being used from Blazor WASM, so this is not the final answer... – Ola Berntsson May 04 '23 at 16:52
  • 1
    Did you find a solution for this? We are also looking to clear up deprecated nuget packages for our blazor solution. – gilm0079 Jun 05 '23 at 16:13
  • Not really, we eventually gave up and just rearranged things, moved dependent code to other libraries and so on. Ultimately we don't have any deprecated references, at least. – Ola Berntsson Jun 07 '23 at 07:19
  • The way I was able to bypass this depreciation issue is to modify the project file and include the reference to "Microsoft.AspNetCore.App". Reference: [https://learn.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-7.0&tabs=visual-studio#only-support-the-blazor-server-hosting-model](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-7.0&tabs=visual-studio#only-support-the-blazor-server-hosting-model) – GTRocker Jun 07 '23 at 15:56
  • 3
    That's what was mentioned in the comments above, but it doesn't work for Blazor WebAssembly. That's why we ended up splitting up libraries for WASM/Server. – Ola Berntsson Jun 08 '23 at 18:22
  • @phuzi your link is broken – Sergio Solorzano Jul 20 '23 at 14:11
  • @SergioSolorzano That other has since been deleted! – phuzi Jul 20 '23 at 18:18

0 Answers0