We're a bit behind the times with all our products (WPF applications) still using v4.6.1. I'm currently having a "play" with .NET 5, and have converted one of our class libraries (used by many of these products) to v5. I'm now attempting to reference this assembly from one of our smaller products, but it's not building, with lots of errors such as:
Dependency "System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". 1> Could not resolve this reference. Could not locate the assembly "System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
I was under the impression .NET 5 was backwards compatible, or does that only apply to .NET Standard? (TBH I've always struggled to get my head around the whole .NET Standard/Core thing).
We don't want to take the plunge and convert the products to .NET 5 just yet - that's a long-term strategy. It would have been nice to have the above class library converted ready for when we do start, so is there any way that a .NET framework solution can reference the .NET 5 assembly? I'm guessing this is impossible, and the only option would be to multi-target? If so how do I do this, and will it go back as far as v4.6.1? Or are we stuck with the "big bang" approach of converting everything to .NET 5 at the same time?
Not sure if it's relevant but in the \bin\debug\
folder of the class library I can see various subfolders such as net5.0
, net5.0-windows
, net472
, netstandard2.1
- only net5.0-windows
contains the built DLL. We may be able to work with 4.7.2 if that's the minimum it'll go back to, but I can't figure out how to multi-target in the first place. In the "Target framework" dropdown I only see .NET 5.0, .NET Core 3.0, .NET Core 3.1.
Edit 1
I followed Camilo's suggestion below to replace with:
<TargetFrameworks>net5.0-windows;net461</TargetFrameworks>
Now, the code won't build. Looking at one example it seems to be complaining that it can find the type "ItemsControl" for .Net5 but not 4.6.1:
I'm assuming I need to add System.Windows.Controls for v4.6.1 somehow, although this is unintuitive at best - as there is no Add Reference -> Assemblies window that you'd find in a .Net framework application. I'm assuming this must now be done via NuGet, and if so which package do I need?