Question

Use of NETStandard 2.0 in NET 8.0 project, conflicts with NETStandard 2.1

I have migrated to NET 8.0 all my NET 4.6.2 projects, except one that's a VTSO Add-in project (Office). Since Web Office addins is the only option offered in NET Core and doesn't have all the features I need for that project, I have no choice to remain in NET Framework for that specific project.

So, I have bundles all the libraries I used commonly and put them in a NETStandard 2.0 library project so it can be used in both NET Core projects, and this one NET Framework project. Which seemed to work just fine, EXCEPT...

There was a conflict between "netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" and "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".
8>        "netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was chosen because it was primary and "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was not.
8>                    logMessageDetails=    References which depend on "netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" [C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.7\ref\net8.0\netstandard.dll].
8>            C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.7\ref\net8.0\netstandard.dll
8>              Project file item includes which caused reference "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.7\ref\net8.0\netstandard.dll".
8>                C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.7\ref/net8.0/netstandard.dll

NETStandard 2.1 is inherently in NET 8.0, so even though NETStandard 2.0 is supported in NET 8.0, it gives conflict error.

Libraries references by NETStandard are also conflicting:

There was a conflict between "System.ComponentModel.Annotations, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
There was a conflict between "System.Management, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

I'm hoping there is a way around that, isn't it supposed to be the purpose of NETStandard to be able to share pieces of code such as interfaces and models, between .NET Core and .NET Framework?

 3  166  3
1 Jan 1970

Solution

 0

Thank you @gunr2171, I made a copy of the project with the conflict and it's dependencies and I started removing dependencies 1 by 1. Turns out the issue was Microsoft.Bcl.Build.

Minimal reproductible example was with two library projects, 1x NET 8.0 that depends on 1x NETStandard 2.0 project. Just Microsoft.Bcl.Build as NET 8.0 project's dependency was enough to reproduce the conflict warning.

@Ralf I'm aware of it, and we plan to phase it out in the future, but we can't do that just yet

@Gabor Oh! thank you! I wasn't aware it is now an option, I think Microsoft.Build.Bcl did warn for it, but this might be the real solution

2024-07-12
Bru