简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM