10

I have a library written using .NET Core, targetting .netstandard2.0. According to this site it should be compatible to use the that version of a .NET Core library with .NET 4.6.2 and 4.6.1. However, when I try to build my .NET Framework library, I get this error:

Project 'c:\myproj.csproj' targets '.NETStandard,Version=v2.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.6.2'.

I'm using Visual Studio 2017 to build the libraries. Is what I'm doing not possible/supported and I'm just misinterpreting the information on the website? The .NET Framework library is referencing System.Management.Automation and is a PowerShell Module, but references code in the .NET core library that is being used in other projects as well.

mhaken
  • 1,075
  • 4
  • 14
  • 28
  • 1
    http://stackoverflow.com/questions/42254288/referencing-a-net-standard-library-from-a-windows-class-library/42364427#42364427 – meziantou Apr 19 '17 at 14:14

2 Answers2

9

I resolved this issue by placing this in the tag:

    <TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
    <TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)'=='net'">.NETFramework</TargetFrameworkIdentifier>
    <TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)'=='netstandard'">.NETStandard</TargetFrameworkIdentifier>

This allowed me to build the .NET Framework class library referencing the .NET core project. Not what I expected from the documentation, since it makes it seem like .netstandard is the new PCL, but it works.

mhaken
  • 1,075
  • 4
  • 14
  • 28
  • what "tag" did you put that in? Where is that? – mcmillab Oct 30 '18 at 04:26
  • @mcmillab In the csproj file undedr . You should see an existing TargetFramework in the xml. – mhaken Oct 30 '18 at 17:56
  • @mhakan thanks that worked. For others just to be clear this is in the csproj file for the dotnetCore library, and it replaces the existing TargetFrameworks line. – mcmillab Oct 31 '18 at 20:24
0

At the time of writing, VS 2017 does not directly support daily builds / preview 2.0 tooling. The SDK that is included with VS 2017 (15.0,15.1) doesn't know about netstandard 2.0 and neither does the integrated NuGet extension.

See https://github.com/aspnet/Announcements/issues/231 for a few workarounds to use preview tooling in the currently released VS 2017 versions.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • I had the same issues targetting netstandard1.6 and netstandard1.5 as well, so I don't think this was necessarily specific to 2.0. I tried with the class library targeting 1.6 and got Project 'C:\myproj.csproj' targets '.NETStandard,Version=v1.6'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.6.2'. – mhaken Apr 20 '17 at 00:01
  • This is because 4.6.2 doesn't support 1.6 libraries using the released tooling (1.0.*) – Martin Ullrich Apr 20 '17 at 13:07
  • Had the same result with .netstandard1.5, which the website says is supported with 4.6.2. – mhaken Apr 21 '17 at 14:14