简体   繁体   中英

Reference .net461 assembly from netstandard 2.0

According to Microsoft ("Reference .NET Framework libraries from .NET Standard") we can reference full framework libraries <= .NET 4.6.1 from .NetStandard 2.0 projects to help with the migration of existing code starting with Visual Studio 15.3

So why does the following not work?

NetStandard/NetStandard.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\FullFramework\FullFramework.csproj" />
  </ItemGroup>
</Project>

FullFramework/FullFramework.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
</Project>

Gives me the following error:

  error NU1201: Project FullFramework is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Project FullFramework supports: net461 (.NETFramework,Version=v4.6.1)
  error : Project '..\FullFramework\FullFramework.csproj' targets 'net461'. It cannot be referenced by a project that targets '.NETStandard,Version=v2.0'.

This feature works if you reference projects which use "old" .csproj format (and target .NET 4.6.1 or less), or it you reference library (.dll file) directly, but for unknown (for me) reason - doesn't work if you reference project with .csproj in "new" format (like in your question). One can argue that because this feature goal is to enable easier porting of old code - it makes some sense that projects in new format are not supported, thought I suppose it's more an oversight than intentional.

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