Target .NET base class library from .NET Framework 4.6.2 Class library

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

Project 'c: \ myproj.csproj' target '.NET Standard, Version = v2.0'. It cannot be referenced in a project whose purpose is ".NETFramework, Version = v4.6.2."

I am using Visual Studio 2017 to create libraries. Is that what I cannot / support and am I just misinterpreting the information on the website? The .NET Framework library references System.Management.Automation and is a PowerShell module, but refers to code in the .NET core library, which is also used in other projects.

+4
source share
2 answers

I solved this problem by putting it in a tag:

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

This allowed me to create a .NET Framework class library that references the main .NET project. Not what I expected from the documentation, as it looks like .netstandard is a new PCL, but it works.

+4
source

VS 2017 / 2.0. SDK, VS 2017 (15.0, 15.1), netstandard 2.0, NuGet.

https://github.com/aspnet/Announcements/issues/231 VS 2017.

0

Source: https://habr.com/ru/post/1675178/


All Articles