0
votes

I am starting to refactor my Blazor project so that I have a Razor Component Library project for my components. Using Visual Studio 2019 this creates a razor component library which targets .NET Standard 2.0.

A potential blocker is that my component has a dependency upon a .NET Core 3.1 class library.

Can anyone suggest how to approach this?

(a) Try to abstract out the dependency, not sure that would be possible because of a necessary dependency graph no matter what, (b) Convert my .NET Standard 2.0 RCL to .NET Core 3.1, would this then make it incompatible to be used in my Blazor .NET Core 3.1 project?

Any advice welcome.

1
If your component has a dependency on a .NET Core 3.1 then it can't be .NET Standard anything - only .NET Core 3.1 (or later) can have a dependency of .NET Core 3.1. Did you mean .NET Standard 2.1 ?Quango
@Quango Visual Studio created my new RCL as .NET Standard 2.0. I’m happy to change what it targets I just want to make sure that if I change it to target .NET Core 3.1 it will work with my consuming Blazor app.phil
It will work if the Blazor app is .NET core 3.1 and uses server side Blazor. Since the web-assembly (WASM) version uses .NET standard you're going down a one-way street, and you can't migrate to that model.Quango
@Quango Oh, that's very good to know re: porting to WASM.phil
.NET Standard is just an "interface" whereas .NET Core is an implementation. I'd hope that any library targets either .NET Standard 2.0 or 2.1Quango

1 Answers

0
votes

Think of .NET Standard as an interface and the individual frameworks (.NET Core, .NET Framework, Mono, Unity, Xamarin, etc.) as implementations. .NET Core 3.1 implements .NET Standard 2.1, so if you have a library that's targeting .NET Standard 2.0, you cannot reference a .NET Core 3.1 library from it, as it's a different interface. You must either target .NET Core 3.1 directly or target .NET Standard 2.1.

Bear in mind, though, that currently client-side Blazor uses the Mono framework for web assembly, and currently, Mono implements .NET Standard 2.0, not 2.1. That means that if you target your library to .NET Core 3.1/.NET Standard 2.1, you can only use it in server-side Blazor apps. If you need/want to support client-side Blazor as well, then you'll have to remain targeted to .NET Standard 2.0. In that case, you'll need to also target your other library to .NET Standard 2.0, if you need to reference it from this one.