Search code examples
c#asp.net-coresignalrsignalr-hub

How can I reference the Hub class in a class library?


I see from the documentation that the Hub class is in package Microsoft.AspNetCore.SignalR. However, when I look at the package in NuGet, it says it has been deprecated.

I see that the Hub class comes automatically in, say, a web API project, but how can I reference it in a class library (without using a deprecated package)?


Solution

  • From this article, you could find the signalR is included inside the Microsoft.AspNetCore.App shared framework.

    So there is no need to install the package, just include the framework inside the proj as below:

      <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
      <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
      </ItemGroup>
    </Project>
    

    Result:

    enter image description here