简体   繁体   中英

.NETStandard Library 1.6.0 dependency in .NET Core application

Using Visual Studio 2015 ASP.NET Core application uses class library ASP.NET Core application and class library had .NET Framework 4.5.2 platform when projects were creating Class library have .NETStandard Library 1.6.0 dependency Will this application launch on .NET Core target runtime or it will require full .NET Framework?

Here is some snapshots

solution explorer of .net core class library

project.json of .net core class library

According to https://docs.microsoft.com/en-us/dotnet/articles/standard/library .NET Core 1.0 implements .NET Standard 1.6.

So yes, your .NET Standard 1.6 library is compatible with .NET Core applications. The .NET 4.5.2 application will not work with it however, as no .NET framework version has implemented 1.6 yet.

According to your attached screenshots, your class library will only be compatible with .NET Core and will not require with .NET Framework.

By the way, it's important to understand the distinction between NETStandard.Library , the NuGet package and ".NET Standard" , the target framework.

In a nutshell:

.NET Standard , the target framework, is a API spec. A project that only targets netstandard1.6 isn't a .NET Core app yet. Here's a very useful analogy: https://gist.github.com/davidfowl/8939f305567e1755412d6dc0b8baf1b7

NETStandard.Library is a package https://www.nuget.org/packages/NETStandard.Library/1.6.0 . This is actually a metapackage ie it contains dozens of other packages like System.Collections.Generic and System.Console. These provide the C# compiler with info about what is in .NET Standard (the API spec) so that it knows which APIs you can use. This means can add "NETStandard.Library v1.6.0" as a dependency to more than just .NET Standard 1.6.

Also, FYI - if you use Visual Studio 2017 and csproj instead of project.json, you don't need to list NETStandard.Library in your project file. It's automatically available.

To resolve this, I did the following to the NetStandard 1.6.1 project's csproj :

 <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard1.6</TargetFramework> <!-- BEGIN INSERTION --> <NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion> <PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <!-- END INSERTION --> </PropertyGroup> <ItemGroup> <PackageReference Include="[some stuff here]" Version="[some stuff here]" /> <PackageReference Include="[some stuff here]" Version="[some stuff here]" /> <PackageReference Include="[some stuff here]" Version="[some stuff here]" /> </ItemGroup> <ItemGroup> <ProjectReference Include="[some stuff here]" /> </ItemGroup> </Project> 

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