Standard: Cannot access fields declared in a .NET Standard 2.0 library from a .NET Framework 4.6.1 application

Created on 15 May 2017  路  3Comments  路  Source: dotnet/standard

I'm currently testing .NET Standard 2.0 with Visual Studio 15.3 Preview, since we are going to build a NET Framework 4.6.x and ASP.NET Core 2.0 (.NET Core 2.0)
So we think that the best way to organized shared libraries is to compile them against .NET Standard 2.0 (so we can benefit from reach APIs compared to .NET Standard 1.3 and a wider pool of NuGet packages).

I have tried to create a simple test application as proof of concept, but for some reason even a simple public static Dictionary field declared in .NET Standard lib is not usable in .NET console application.
Visual Studio suggests that .NET Framework console application must reference netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 which for me doesn't make any sense 馃槴

image

I tried to add a NETStandard.Library via NuGet, but it didn't help.
So at this point I'm wondering if it's a bug or I'm missing the whole .NET Standard 2.0 thing.

This repository contains the code which reproduces the problem I'm currently experiencing on my PoC solution:

https://github.com/salaros/netstandard.v2_0.test

Most helpful comment

The .NET Framework project needs the NETStandard.Library.NETFramework package. I would also recommend moving away from packages.config and moving to PackageReference:

image

All 3 comments

The .NET Framework project needs the NETStandard.Library.NETFramework package. I would also recommend moving away from packages.config and moving to PackageReference:

image

Thank you! It worked, but I have to say that without your help I would never figured out what is the right NuGet package for .NET 4.6.x (NETStandard.Library.NETFramework or NETStandard.Library)

  • I thought that using PackageReference or packages.config were basically almost the same thing.

So IMO Visual Studio must suggest one installing NETStandard.Library.NETFramework rather than referencing netstandard, Version=2.0.0.0, Culture=neutral (like it's doing on the screenshot above).
As for packages.config I don't know what to say, if it breaks new features, such as .NET Standard 2.0 - then just stop supporting it in Visual Studio 15.3 and newer, like you will probably do with PCLs according to this video... or just make it clear when it's OK using packages.config and when it's not

Thank you again!

So IMO Visual Studio must suggest one installing NETStandard.Library.NETFramework rather than referencing netstandard, Version=2.0.0.0, Culture=neutral (like it's doing on the screenshot above).

I pinged @terrajobst about a roslyn code fix that does this.

As for packages.config I don't know what to say, if it breaks new features, such as .NET Standard 2.0 - then just stop supporting it in Visual Studio 15.3 and newer, like you will probably do with PCLs according to this video... or just make it clear when it's OK using packages.config and when it's not

It desnt break, it's just ALOT rougher of an experience.

Was this page helpful?
0 / 5 - 0 ratings