【问题标题】:create multi target nuget package创建多目标 nuget 包
【发布时间】:2019-07-24 19:10:47
【问题描述】:

嗨,我想创建多目标 nuget 包。一切似乎都运行良好除了当我创建 wpf NetCore3 应用程序并安装我的包时使用 .NET Framework dll 而未使用 NetCore3 库

<files>
    <file src="lib\netcore\Control.dll" target="lib\netcore" />
    <file src="lib\net48\Control.dll" target="lib\net48" />
    <file src="lib\net40\Control.dll" target="lib\net40" />
    <file src="lib\net40\Microsoft.Windows.Shell.dll" target="lib\net40" />
  </files>

lib\netcore 正确吗?

【问题讨论】:

    标签: nuget nuget-package nuget-spec


    【解决方案1】:

    您应该在包中使用与 csproj&lt;TargetFramework&gt; 元素中相同的 TFM。如果您的csproj 具有&lt;TargetFramework&gt;netcore&lt;/TargetFramework&gt;,那么请使用lib/netcore/whatever.dll。但是如果你的csproj&lt;TargetFramework&gt;netcoreapp3.0&lt;/TargetFramework>,那么你应该使用lib/netcoreapp3.0/whatever.dll

    但是,SDK 样式项目是唯一适用于 .NET Core 3.0 的类型,支持多目标(将 &lt;TargetFramework&gt; 更改为 &lt;TargetFrameworks&gt;,然后使用分号分隔列表 netcoreapp3.0;net48;net40),并且 NuGet 的包目标知道如何自动打包这些项目。因此无需自己创建nuspec,这样可以最大限度地降低犯此类错误的风险。

    所以,正如NuGet's docs on creating multi-targeting packages 所说,只需使用dotnet pack 创建您的包,然后让NuGet 找出要使用的lib/* 文件夹。避免使用 nuspec 文件。您在 nuspec 中指定的任何其他元数据都可以specified via MSBuild properties in your csproj

    【讨论】:

      【解决方案2】:

      netcore is a Microsoft Store TFM.

      对于您的 .NET Core 3 (netcoreapp3.0) WPF 应用,您需要在 NuGet 包中使用 netstandardnetcoreapp 进行多目标。

      例如:

      &lt;TargetFrameworks&gt;netstandard2.0;net461&lt;/TargetFrameworks&gt;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-22
        • 1970-01-01
        • 1970-01-01
        • 2019-11-12
        相关资源
        最近更新 更多