【问题标题】:Different ways how to deal with package reference in csproj如何在 csproj 中处理包引用的不同方法
【发布时间】:2019-06-04 17:48:34
【问题描述】:

到目前为止,我一直在使用属性来控制 PackageReference 的资产依赖关系(第一个示例)。最近,在使用 NuGet 包管理器(在 VS 中)之后,我最终得到了完全不同的 XML。

两者都在控制相同的东西,谁能帮我理解差异和需要两种方法来控制类似的东西吗?

Additions to the csproj format for .NET Core > PackageReference

<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0" PrivateAssets="..." IncludeAssets="..." ExcludeAssets="..." />

Package references (PackageReference) in project files > Controlling dependency assets:

<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0">
    <IncludeAssets>...</IncludeAssets>
    <ExcludeAssets>...</ExcludeAssets>
    <PrivateAssets>...</PrivateAssets>
</PackageReference>

【问题讨论】:

    标签: c# .net-core csproj


    【解决方案1】:

    这些在功能上是等效的。除了一个例外,在&lt;PackageReference&gt; 元素上使用属性是让嵌套元素具有相同名称的快捷方式。例外是 Include 属性,它不能是嵌套元素。

    因此,Visual Studio、MSBuild、NuGet 等将一视同仁:

    <PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0" />
    <PackageReference Include="Contoso.Utility.UsefulStuff">
      <Version>3.6.0</Version>
    </PackageReference>
    

    “ExcludeAsset”等其他属性也是如此。

    在使用 NuGet 包管理器(在 VS 中)之后,我最终得到了完全不同的 XML。

    VS 中的 NuGet 包管理器在修改您的 &lt;PackageReference&gt; 时不遵守文档的原始格式。 NuGet 可能正在获取 .csproj 文件的解释结果,而不是原始 XML,因此它不知道您使用的是属性还是嵌套元素。

    【讨论】:

      猜你喜欢
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 2013-02-20
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      相关资源
      最近更新 更多