SignalR cannot be used with .Net Core

2019-03-26 13:22发布

问题:

I am trying to install SignalR using NuGet package manager in my C# Asp.Net core project, but I get this error that SignalR is not compatible with .net core, is it really not supporter yet? or can I do something to get it work? (I am using VS2017 if it was important to mention that). The error:

Restoring packages for D:\Test\Test.WebAPI\Test.WebAPI.csproj...
Package Microsoft.AspNet.SignalR.Core 2.2.1 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.AspNet.SignalR.Core 2.2.1 supports: net45 (.NETFramework,Version=v4.5)
Package Owin 1.0.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Owin 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
Package Microsoft.Owin 2.1.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.Owin 2.1.0 supports:
  - net40 (.NETFramework,Version=v4.0)
  - net45 (.NETFramework,Version=v4.5)
Package Microsoft.Owin.Security 2.1.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.Owin.Security 2.1.0 supports: net45 (.NETFramework,Version=v4.5)
One or more packages are incompatible with .NETCoreApp,Version=v1.1.
Package restore failed. Rolling back package changes for 'Test.WebAPI'.

UPDATE:

SignalR for ASP.Net Core is at the moment (01.01.2018) available in NuGet as alpha version.

https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR/

UDPATE 01.06.2018:

SignalR is now available for ASP.Net Core 2.1

回答1:

SignalR 2 is built for .NET Framework, not for .NET Core. They are still working on SignalR for .NET Core.

An old revision of the ASP.NET Core Roadmap shows SignalR as part of ASP.NET Core 1.2. The latest revision makes no reference to SignalR (or any of the framework) but does mention 1.2 is scheduled for Q2 2017.

There's a video where the Microsoft guys are discussing SignalR in ASP.NET Core. It's an hour long so I'm not going to watch it for you. But perhaps some useful information is in there.



回答2:

I'm currently working on a .net core / angular 4 project using signalr.

There are a handful of seed examples on google, but one thing which may trip most people up trying to download signalr via nuget is the fact that it's a different package repo - you need to update Nuget.config in your solution to reference the more bleeding edge repo:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>


回答3:

SignalR for asp.net core

EDIT: SignalR for asp.net core has been released with .net standard 2.1.

This package targets .net standard 2.0 and is still in the alpha state.

It doesn't seem like a stable release is out before .net standard 2.1.

The packages can be found on myget.

If you load balance your signalr hub you can use redis as backpane.


SignalR for asp.net

And there is also the SignalR package for the .net framework which allready has a stable release. It can be found on nuget.

For load balancing the following backpane types are supported:

  • Azure Service Bus
  • Redis
  • SQL Server

SignalR.Server for asp.net core (update 18.09.2017: not available anymore)

Do not use this package!

This is the deprecated package which targets .net 4.5.1 and .net standard 1.6. No stable package has and will ever be released.

The preview packages can be found on myget.

If you load balance your signalr hub you can use sql server as backpane. (But the implementation is broken)



回答4:

That is correct. SignalR is built on OWIN, which is compatible with asp.net core if you target the full framework, but not dotnet core.



回答5:

I recently migrated an MVC5 application that used SignalR to ASP.NET Core 1.1 (netcoreapp1.1). I found an unofficial package (Gray.Microsoft.AspNetCore.SignalR.Server) that worked straight almost without any changes to my existing code.

csproj file

<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="1.0.2" />
<PackageReference Include="Gray.Microsoft.AspNetCore.SignalR.Server" Version="0.2.0-alpha1" />

Startup - ConfigureServices method

services.AddSignalR();

Startup - Configure method

app.UseWebSockets();
app.UseSignalR();


回答6:

The following packages can be found on NuGet.

Microsoft.AspNetCore.SignalR 1.0.0-alpha1-final Components for providing real-time bi-directional communication across the Web.

Microsoft.AspNetCore.SignalR.Redis 1.0.0-alpha1-final Redis for ASP.NET Core SignalR.

The packages supported .NETSTandard,Version=v2.0 Now. I used the packages in my projects. Angular 4 + SignalR



回答7:

SignalR is introduced with .NET Core Here is the link for implementation https://www.youtube.com/watch?v=1TrttIkbs6c