1

I have a .NET Framework library with NuGet package dependencies. This library is consumed exclusively by .NET Framework projects. Some of them by local project references, and most through NuGet. I publish the library to a private NuGet server.

A few projects have cropped up using .NET Core based infrastructure, and I would like to make my standard library available to these projects. I am not switching any of the existing infrastructure to .NET Core. I don't want to introduce .NET Core dependencies into every existing .NET Framework project. I have noticed that when I install certain multi-targeted libraries, sometimes they include "netstandard" or something like that -- and install lots of dependencies. These are unacceptable and get immediately uninstalled from .NET Framework projects.

Is it possible to multi-target my .NET Framework (4.72 if it matters) project to .NET Core as well, while still producing native .NET Framework libraries? I can copy and paste all the code in my library into a netcoreapp3.1 project, install NuGet dependencies, and that code runs fine. However, I don't want to port this library to .NET Core, and then multi-target it back to .NET Framework. As far as I am aware, that is not the same as having a native implementation. I just want to be able to use the library in a .NET Core app without copying and pasting the entire library, and letting the versions get out of sync. The less ceremony the better.

My csproj file doesn't have a <TargetFramework or <TargetFrameworks> property. It has a <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> property.

Is what I'm trying to do possible? I can't tell from the documentation I have read.

Erasmus
  • 596
  • 5
  • 8
  • The reason you see all those dependencies pulled in is because your projects are using ancient versions of the .NET Framework that lack many types that are now part of the .NET BCL. – Ian Kemp Sep 30 '20 at 21:14
  • @IanKemp .NET 4.7.2 is hardly *ancient* :) – Camilo Terevinto Sep 30 '20 at 21:17
  • I can upgrade to .NET 4.8, which is the most current. I've always kept using the most up to date framework version that I can. – Erasmus Sep 30 '20 at 21:18
  • Cannot you target .NET Standard 2.0 from the library? The library itself might need some extra dependencies, but the .NET Core and .NET Framework project likely won't import them. – Camilo Terevinto Sep 30 '20 at 21:19
  • @CamiloTerevinto The library is on 4.7.2 which should not require too many shims to bring it up to parity with .NET Standard 2.0, but anything older than that will pull in a whole bunch of dependencies. I'm assuming the projects that are mentioned are in that boat. – Ian Kemp Sep 30 '20 at 21:30
  • @Camilo Terevinto I am not sure how that would work. If you know more and want to write it up, please do! That doesn't sound like multi-targetting however. The netstandard thing is confusing to me, because I have never seen it be of any use. – Erasmus Sep 30 '20 at 21:58
  • It's correct that .NET Standard isn't multi-targetting, but you can think of .NET Standard 2.0 as "the base interface" of .NET Framework and .NET Core. An answer would be long, and there are some good docs around in Microsoft Docs. However, I'm completely assuming (and hence the question in the comment) that the library is *a library* (i.e no web frameworks, no UI code, etc, etc) – Camilo Terevinto Sep 30 '20 at 22:01
  • @IanKemp Anything newer than 4.6.1 should already support .NET Standard 2.0: https://learn.microsoft.com/en-us/dotnet/standard/net-standard - so 4.7.2 would definitively work here. By multi-targetting, however, I think many dependencies from the .NET Core world would need to be imported (but I may be wrong :)). – Camilo Terevinto Sep 30 '20 at 22:02
  • It's actually 9 libraries, with one central library. They are .NET "Library" projects in the VS creation wizard. I've tried to isolate idiosyncratic dependencies. One library has extensions for the now defunct NancyFX, which is a web framework, but one that has multiple hosting adapters, so referencing the base project is like referencing an actual library. – Erasmus Sep 30 '20 at 22:10
  • Which SDKs will I need to enable netstandard 2.0? .NET Core 2.0? 2.1? 3.1? Microsoft has .NET Core 2.0 marked as EOL. https://dotnet.microsoft.com/download/visual-studio-sdks – Erasmus Sep 30 '20 at 22:57
  • Nevermind, I have .NET Core stuff installed already, it's just not available in the drop down. It would probably be necessary to delete the project and recreate it. – Erasmus Sep 30 '20 at 23:13
  • I don't think there's a one-click way of converting .NET Framework -> .NET Standard. I think the easiest would be to create an empty .NET Standard library project and copy the CSProj format to your actual library project and start adding packages/etc – Camilo Terevinto Oct 01 '20 at 16:34

0 Answers0