Visual Studio 2017 won't load .NET Framework references in .NET Standard library
When multi-targeting both .NET Framework and .NET Core/.NET Standard you will almost certainly need to use MSBuild Conditions to prevent .NET Framework references from bleeding over into .NET Core/.NET Standard.
MSBuild conditions have been around for quite some time, but there is no support in Visual Studio to add them, you have to manually edit your .csproj
file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Utility\EncryptionUtility.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Utility\" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Runtime.Caching" />
</ItemGroup>
</Project>
Also note that once you do this, there are no guarantees it will work right to add a NuGet or other assembly reference using Visual Studio - you may need to do manual cleanup every time in the
.csproj
file to ensure the reference is added to the right conditional section. You are probably better off adding references by hand-editing the file every time.
On my side, I've tried all the solution presented before but the solution was simply install NuGet package for Microsoft.CSharp.
After installation just clean the project and restart your IDE.
Try to change order of TargetFrameworks inside your .csproj.
From
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
To
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>