18

I have a NET6 project which is built part of a larger .NET 6 ASP.NET solution. The project still references:

  1. Microsoft.AspNetCore.SignalR, and
  2. Microsoft.AspNetCore.SignalR.Core

Which have now been marked as deprecated.

What packages do I need to install for their replacement?

The problem is that currently SignalR is located in an assembly separate from the main ASP.NET project. This is because the main project and a couple of other projects within the solution use the hubs (using constructor DI).

If I change the SignalR project to

<Project Sdk="Microsoft.NET.Sdk.Web">
    ...
</Project>

I get the following compilation error:

Error CS5001 Program does not contain a static 'Main' method suitable for an entry point

So the problem is that I cannot have a common assembly with SignalR referenced by multiple other projects.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • You could check out this - https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Core/. Here it says that Microsoft.AspNetCore.SignalR.Core is deprecated. – AchoVasilev Jun 23 '22 at 18:40

2 Answers2

19

SignalR is included in the Microsoft.AspNetCore.App shared framework (docs). Change the console app SDK to Microsoft.NET.Sdk.Web:

<Project Sdk="Microsoft.NET.Sdk.Web">
   ...
</Project>

To use the ASP.NET Core shared framework in a class library project - add FrameworkReference element for Microsoft.AspNetCore.App:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • This works only if the project is the main one. I have SignalR in a separate project in which I define my hubs and is reference in the main ASP.NET project and other projects within the solution. – Ivan-Mark Debono Jun 24 '22 at 03:02
  • @Ivan-MarkDebono "This works only if the project is the main one" - can you please elaborate? You can't change the separate project to target web sdk? – Guru Stron Jun 24 '22 at 09:26
  • Doing so requires that the project has a static 'Main' method. – Ivan-Mark Debono Jun 25 '22 at 03:35
  • 1
    @Ivan-MarkDebono see the update. – Guru Stron Jun 25 '22 at 09:50
  • @Ivan-MarkDebono Can also just change the output type in the project file: `Library`. The reason it requires a Main method is because by default it will be `Exe` – rism Sep 21 '22 at 07:22
  • @MohammadTaherian which one? – Guru Stron Jun 29 '23 at 17:11
  • @MohammadTaherian please read the answer, it does not say to add package. And the [frameworkreference](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-7.0) it says to add is far from being deprecated. – Guru Stron Jun 29 '23 at 18:46
1

Server-side SignalR is nowadays a part of the NET base class library. You don't need any server-side packages. The Microsoft.AspNetCore.SignalR namespace classes are just there.

However, you need the client-side package, the @microsoft/signalr@latest.

In case of further issues, please consult the documentation.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
  • _"(...) are just there."_ **IF** your project happens to just have the ASP.NET Core framework reference. – Prolog Jun 29 '22 at 13:01
  • @Prolog: thanks for this, however, I believe it's obvious. .NET Framework and .NET Core have huge base class libraries and of course, to use parts of the library you always need to setup references. The *there* in my *namespace classes are just there* refer to the BCL, I didn't even mentioned specific projects. – Wiktor Zychla Jun 29 '22 at 13:13
  • 1
    I believe you're mistaken. SignalR's `Hub` is not part of BCL, while `Stream` is. It would be only obvious if there was no need for setting up a framework reference in projects that do not have it by default, such as class library projects. If SignalR's `Hub` was part of BCL, then yes, it would be obvious. – Prolog Jun 29 '22 at 14:58
  • @Prolog: I see your point and yes, if the asp.net core is somehow not classified as part of the net core back then you are right and this should be reflected possibly in my answer. I'll double check that then. – Wiktor Zychla Jun 29 '22 at 20:27