新版的nuget包 PackageLicense 這樣寫
阿新 • • 發佈:2018-12-31
Intro
最近編譯類庫專案的時候發現總是有個 licenseUrl 的警告,警告資訊如下:
warning NU5125: The 'licenseUrl' element will be deprecated. Consider using the 'license' element instead
本文針對的是使用新版專案檔案打包的方式,*.nuspec 官方文件詳細,在此不多說。
新版的官方文件裡基本沒有提及,不過 Github 有個 samples 專案,可以參考。
新版專案檔案的 nuget 包原來可以指定一個 PackageLicenseUrl
來指定這個包的 license, 現在不再支援了,現在有兩種方式可以指定,一種是 LicenseExpression
LicenseFile
。
LicenseExpression
示例:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <PackageLicenseExpression>MIT</PackageLicenseExpression> <!-- <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> --> </PropertyGroup> </Project>
更多license列表可以參考:https://spdx.org/licenses/
LicenseFile
增加 license file,具體的 license 寫在 license file 內,並配置打包,然後配置 PackageLicenseFile
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>netstandard2.0</TargetFrameworks> <PackageLicenseFile>License.txt</PackageLicenseFile> </PropertyGroup> <ItemGroup> <None Include="License.txt" Pack="true" Visible="false" PackagePath=""/> </ItemGroup> </Project>