Reputation:
I've inherited a bunch of net framework 4.71 solutions, and two net core 2.1 solutions.
I need to write a library for blob storage that can be used by both of them. I found that the net framework won't call a net core library, and a net core framework won't call the net framework library. So I was in the midst of trying a couple of net standard 2.1 libraries. (one for external models and one for the blob storage functions)
I haven't even gotten to the point of making sure that the net core and net framework projects can reference net standard libraries.
Question 1) can net framework and net core reference net standard libraries?
Question 2) is there a way to even share code between net core and net framework or should I just work on creating duplicate libraries?
Edit: I did just finally figure out what I was doing wrong in referencing the net standard model project from the blob storage net standard project. I had to add the project reference directly. Haven't had to do that in a long time. Visual Studio would add it for me with net framework.
Edit2: looks like I'm just an idiot. I finally figured out that I needed to also manually add the project reference for the library to the net core project. Now it compiles. Thanks everyone.
Upvotes: 1
Views: 2378
Reputation: 36341
In additional to the excellent answer by Marc I would like to add the .net standard support matrix that shows what .net version support what .net standard version.
The way I understand it, the intended migration strategy is something like this
This way should limit the number of projects that need to be updated at once. Allowing migration to be done piecemeal rather than all at once.
Upvotes: 0
Reputation: 1062745
can net standard libraries reference other net standard libraries?
yes; a netstandard2.0 library can reference another netstandard2.0 library; a netstandard2.1 library can reference netstandard2.0 and netstandard2.1 libraries
can net framework and net core reference net standard libraries
.NET Framework 4.7.1 can allegedly reference netstandard2.0 libraries, although it has some assembly-binding-redirect problems in a few areas ("unsafe", "buffers", etc) - and some areas are simply glitchy; it cannot reference netstandard2.1 libraries
.NET Core can reference netstandard libraries; these days you shouldn't really be looking at .NET Core below .NET Core 3.1, which means it can reference both netstandard2.0 and netstandard2.1 libraries
is there a way to even share code between net core and net framework or should I just work on creating duplicate libraries
multi-targeting is also an option, if netstandard doesn't work well for you; you can use <TargetFrameworks>netcoreapp3.1;net471</TargetFrameworks>
, for example, and use #if
as necessary to switch between target-specific implementations.
Upvotes: 5