Search code examples
.netnugetvisual-studio-2017.net-standard.net-4.6.2

How do you reference a netstandard project from .net project in VS2017?


I have a netstandard2.0 project that I'm using to interface with a 3rd party web service. I need to reference that project from an older .net 4.6.2 project in the same solution, but when I do I get a bunch of errors about needing references to types that I have defined.

For example, I'll call a method in the netstandard library that returns Task, but I'll get an error saying I need a reference to System.Threading.Tasks even though I already have one.


Solution

  • I believe there are two issues here.

    Only certain version of .netstandard work with certain versions of .net 4.X.Y

    To resolve this you may need to change the version of one or both projects. Use the chart to figure out which versions are compatible together: https://learn.microsoft.com/en-us/dotnet/standard/net-standard

    1. Select your project
    2. Right click for properties
    3. On the "Application" tab use the "Target Framework" drop-down to change framework as needed

    .net 4.X.Y uses the 4.0.0.0 system libraries, whereas .netstandardX.Y uses 4.3.0.0

    To resolve this you need to add and reference the netstandard.library NuGet package.

    1. Select your project
    2. Right click for "Manage NuGet Packages..."
    3. On the "Browse" tab search for "netstandard.library"
    4. Select the version you need and install it (I believe it's based on what version of .netstandard you ended up using)
    5. Navigate to each reference error, right click on it, and add whatever reference is missing