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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章