简体   繁体   English

使用 .nuspec 创建多目标 nuget 包

[英]Creating multitarget nuget package with .nuspec

I have specified multitargeting in my .csproj我在我的 .csproj 中指定了多目标

<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>

When I am using below script, then my package has dependencies and it is expected result:当我使用下面的脚本时,我的包有依赖项,这是预期的结果:

dotnet pack --output nupkgs $ProjectPath -c:Release

The problem is when I also want to use .nuspec file with some information about package:问题是当我还想使用 .nuspec 文件和一些有关包的信息时:

dotnet pack --output nupkgs $ProjectPath -c:Release -p:NuspecFile=$NuspecFile 

With .nuspec file the package has no dependencies and I can install it only in netstandard2.0...使用 .nuspec 文件,该包没有依赖项,我只能在 netstandard2.0 中安装它...

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>xyz</id>
    <version>1.2011.4</version>
    <title>xyz</title>
    <authors>xyz</authors>
    <projectUrl>xyz</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>xyz</description>
    <copyright>xyz</copyright>
  </metadata>
</package>

Should I add something to this .nuspec to have a package with target dependencies?我应该向这个 .nuspec 添加一些东西来拥有一个包含目标依赖项的包吗? I have read about tag, but to be honest I cannot find example how to configure it.我已经阅读了有关标签的内容,但说实话,我找不到如何配置它的示例。

Given that you are using an SDK based projects, I'd strongly discourage using a nuspec unless your scenario cannot be satisfied because of it's complexity.鉴于您使用的是基于 SDK 的项目,我强烈建议您不要使用 nuspec,除非您的场景因其复杂性而无法满足。

The automatic package generation with project file through dotnet.exe pack does much of the compatibility work for you.通过dotnet.exe pack使用项目文件自动生成dotnet.exe pack可为您完成大部分兼容性工作。

If you really need to go with a nuspec, you should add dependency groups like defined here:如果您确实需要使用 nuspec,则应添加如下定义的依赖项组:

https://docs.microsoft.com/en-us/nuget/reference/nuspec#dependency-groups . https://docs.microsoft.com/en-us/nuget/reference/nuspec#dependency-groups

Make sure you add the relevant framework.确保添加相关框架。

Example例子

    <group targetFramework=".NETFramework4.7.2">
        <dependency id="PackageA" version="1.2.3" />
    </group>
     <group targetFramework=".NETStandard2.0">
        <dependency id="PackageB" version="4.5.6" />
    </group>

Note that you need to add a dependency group for the specific frameworks you support.请注意,您需要为您支持的特定框架添加一个依赖项组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM