20

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.

1

1 Answer 1

24

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>
Sign up to request clarification or add additional context in comments.

7 Comments

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-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?
Doing so requires that the project has a static 'Main' method.
@Ivan-MarkDebono see the update.
@Ivan-MarkDebono Can also just change the output type in the project file: <OutputType>Library</OutputType>. The reason it requires a Main method is because by default it will be <OutputType>Exe</OutputType>
|

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.