Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target .NET Core Class Library From .NET Framework 4.6.2 Class Library

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.

like image 586
mhaken Avatar asked Apr 19 '17 14:04

mhaken


1 Answers

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.

like image 197
mhaken Avatar answered Oct 16 '22 21:10

mhaken