【问题标题】:Upload NuGet package, how to set the license?上传 NuGet 包,如何设置许可?
【发布时间】:2020-01-01 01:50:24
【问题描述】:

我正在尝试在网站上上传新的 NuGet 包。
https://www.nuget.org/packages/manage/upload

在第一次尝试时,我收到一条错误消息,提示我需要指定许可证。
我不想要,但是……好吧。

因此,我使用指定许可证的第一次尝试失败了。我阅读了链接的文档,并尝试了多次。
我尝试使用 <license> 属性,并在包中包含 license.txt 文件。

这些是我对 .nuspec 文件的尝试以及我收到的错误:

<license type="MIT"/>  
    => Error: Unsupported license type 'MIT'.
    (I know it is wrong but I found this "example" here: https://github.com/NuGet/Home/wiki/Packaging-License-within-the-nupkg)

<license type="expression">MIT</license>   
    => Error: To provide a better experience for older clients when a license expression is specified, must be set to 'https://licenses.nuget.org/MIT'.  

<license type="expression">BSD-2-Clause OR MIT</license>
    => Error: To provide a better experience for older clients when a license expression is specified, must be set to 'https://licenses.nuget.org/BSD-2-Clause%20OR%20MIT'.

<license type="expression">https://licenses.nuget.org/MIT</license>
    => Error: Invalid license metadata: The license expression 'https://licenses.nuget.org/MIT' contains invalid characters.  

我也尝试使用我的 license.txt,但没有成功。

我正在做的是:修改生成的 mylibrary.nupkg 中包含的 mylibrary.nuspec 文件,添加 &lt;license&gt; 字段。
为什么?因为这个 VS studio 项目使用 nuget.exe mylibrary.csproj 文件生成包,并且它不包含许可证。
我更新了 nuget.exe 到最新的 5.1 版本,但是我不想修改 VS 解决方案或项目。

有什么想法吗?

【问题讨论】:

  • 这些错误是在您上传到 nuget.org 时出现的?当我使用nuget pack 时没有看到这些错误。我认为 2) 和 3) 的错误只是说您还应该为老客户包含旧样式的 licenseUrl 元素。
  • nuget 包很好,没有错误。当我使用网站上传页面时出现这些错误。 --- “licenseUrl 已被弃用。请改用许可证。” docs.microsoft.com/en-us/nuget/reference/nuspec#license
  • 我会将这个提交给 NuGetGallery - github.com/NuGet/NuGetGallery/issues

标签: nuget licensing


【解决方案1】:

编辑.csproj 文件。添加以下内容:

使用许可证文件:

    <PropertyGroup>
        <PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
    </PropertyGroup>

    <ItemGroup>
        <None Include="licenses\LICENSE.txt" Pack="true" 

PackagePath="LICENSE.txt"/>
    </ItemGroup>

使用 PackageLicenseExpression:

<PropertyGroup>
  <PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

更多详情,see

【讨论】:

  • 使用这个包许可表达式方法使得“许可接受”窗口(在我的例子中)只显示一个指向 MIT 的超链接,根本没有任何其他文本。这种行为是设计使然还是我做的不对?
  • @mathgenius 也许您需要在您的 nuspec 文件中指定 &lt;requireLicenseAcceptance&gt;false&lt;/requireLicenseAcceptance&gt;?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-23
  • 1970-01-01
  • 1970-01-01
  • 2013-11-02
  • 1970-01-01
  • 1970-01-01
  • 2019-05-11
相关资源
最近更新 更多