简体   繁体   中英

Is SignalR with .NET 5 compatible with a Blazor application running .NET Standard 2.1?

Having a nightmare of a time setting up a simple Blazor SignalR application.

According to documentation, SignalR is greatly improved in .NET 5. It's not compatible with .NET Core 3.1. That's fair enough.

If I make a Blazor web assembly client, not hosted in .NET Core (I don't understand what that really means but I decided not to check the box to do it), then it runs on .NET Standard 2.1

So if I set up SignalR in .NET 5 and then try to consume it using my .NET Standard 2.1 Blazor client, would that work? If not what should I do?

--

Edit: 在此处输入图像描述

If I make a Blazor web assembly client, not hosted in .NET Core (I don't understand what that really means but I decided not to check the box to do it), then it runs on .NET Standard 2.1

If you create a WASM app using .NET Core 3.1 :

  • .NET Core hosted: There will be 3 projects created:

    • .Client is netstandard2.1 and using Microsoft.NET.Sdk.Web SDK
    • .Server will be netcoreapp3.1 and using Microsoft.NET.Sdk.Web SDK
    • .Shared will be netstandard2.1 and using Microsoft.NET.Sdk SDK
  • NOT .NET Core hosted: There will be 1 project created, which is netstandard2.1 and using Microsoft.NET.Sdk.Web SDK

If you create a WASM app using .NET 5

  • .NET Core hosted: There will be 3 projects created:

    • .Client is net5.0 and using Microsoft.NET.Sdk.BlazorWebAssembly SDK
    • .Server is net5.0 and using Microsoft.NET.Sdk.Web SDK
    • .Shared is net5.0 and using Microsoft.NET.Sdk SDK
  • NOT .NET Core hosted: There will be 1 project created, which is net5.0 and using Microsoft.NET.Sdk.BlazorWebAssembly SDK

So if I set up SignalR in .NET 5 and then try to consume it using my .NET Standard 2.1 Blazor client, would that work? If not what should I do?

This should not be a problem. To avoid any further confusion you can easily upgrade your .NET Core 3.1 WASM app to .NET 5 following these steps:

On .csproj file:

  1. Change <Project Sdk="Microsoft.NET.Sdk.Web"> to <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
  2. Change <TargetFramework.netstandard2.1</TargetFramework> to <TargetFramework.net5.0</TargetFramework>
  3. Remove <RazorLangVersion>3.0</RazorLangVersion>
  4. Remove package reference to Microsoft.AspNetCore.Components.WebAssembly.Build
  5. Update all other packages to latest stable 5.0.0

Make sure you have these setup properly on your machine

  1. Latest visual studio https://visualstudio.microsoft.com/downloads/
  2. .NET 5 SDK https://do.net.microsoft.com/download/do.net/5.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM