What are the application implications of a netstandard library depending on a metapackage?

问题:

Suppose I have a class library which I want to target netstandard1.3, but also use BigInteger . 假设我有一个我想要以netstandard1.3为目标的类库,但也使用BigInteger Here's a trivial example - the sole source file is Adder.cs : 这是一个简单的例子 - 唯一的源文件是Adder.cs

using System;
using System.Numerics;

namespace Calculator
{
    public class Adder
    {
        public static BigInteger Add(int x, int y)
            => new BigInteger(x) + new BigInteger(y);            
    }
}

Back in the world of project.json , I would target netstandard1.3 in the frameworks section, and have an explicit dependency on System.Runtime.Numerics , eg version 4.0.1. 回到project.json的世界,我将在frameworks部分中定位netstandard1.3 ,并且对System.Runtime.Numerics有明确的依赖,例如版本4.0.1。 The nuget package I create will list just that dependency. 我创建的nuget包将列出该依赖项。

In the brave new world of csproj-based dotnet tooling (I'm using v1.0.1 of the command-line tools) there's an implicit metapackage package reference to NETStandard.Library 1.6.1 when targeting netstandard1.3 . 在基于csproj的dotnet工具的勇敢新世界中(我使用的是命令行工具的v1.0.1),当针对netstandard1.3时,有一个隐含的 NETStandard.Library 1.6.1 包引用 NETStandard.Library 1.6.1 This means that my project file is really small, because it doesn't need the explicit dependency: 这意味着我的项目文件非常小,因为它不需要显式依赖项:

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

... but the nuget package produced has a dependency on NETStandard.Library , which suggests that in order to use my small library, you need everything there. ...但是生成的nuget包依赖于NETStandard.Library ,这表明为了使用我的小型库,你需要一切

It turns out I can disable that functionality using DisableImplicitFrameworkReferences , then add in the dependency manually again: 事实证明我可以使用DisableImplicitFrameworkReferences禁用该功能,然后再次手动添加依赖项:

<Project Sdk="Microsoft.NET.Sdk">    
  <PropertyGroup>
    <TargetFramework>netstandard1.3</TargetFramework>
    <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Runtime.Numerics" Version="4.0.1" />
  </ItemGroup>    
</Project>

Now my NuGet package says exactly what it depends on. 现在,我的NuGet软件包确切地说明了它所依赖的内容。 Intuitively, this feels like a "leaner" package. 直观地说,这感觉就像一个“更精简”的包装。

So what's the exact difference for a consumer of my library? 那么我图书馆消费者的确切区别是什么? If someone tries to use it in a UWP application, does the second, "trimmed" form of dependencies mean that the resulting application will be smaller? 如果有人试图在UWP应用程序中使用它,第二个“修剪”形式的依赖关系是否意味着生成的应用程序会更小?

By not documenting DisableImplicitFrameworkReferences clearly (as far as I've seen; I read about it in an issue ) and by making the implicit dependency the default when creating a project, Microsoft are encouraging users to just depend on the metapackage - but how can I be sure that doesn't have disadvantages when I'm producing a class library package? 通过不清楚记录DisableImplicitFrameworkReferences (据我所见;我在一个问题中读到它)并通过在创建项目时使隐式依赖成为默认值,Microsoft 鼓励用户只依赖于元数据包 - 但我怎么能当我生产类库包时,确保没有缺点?


解决方案:

参考: https://stackoom.com/en/question/2uCSl
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章