The past couple of days I've been getting warnings when compiling my .NET Standard/Core projects:
NuGet.Build.Tasks.Pack.targets(202, 5): [NU5125] The 'licenseUrl' element will be deprecated. Consider using the 'license' element instead.
To fix this, I switched to using <PackageLicenseFile>...</PackageLicenseFile>
instead of <PackageLicenseUrl>...</PackageLicenseUrl>
.
However, in order for this to work, I have to add the license file to my package (naturally), but it gets added to the content
and contentFiles
directory, which means that a project using this package gets the license file added to it.
Is there a way to embed the license file so that PackageLicenseFile
works correctly, without adding the license file to projects using the package?
This is the section I added to the .csproj file in order to embed the license file:
<ItemGroup>
<Content Include="..\LICENSE" />
</ItemGroup>
The output package structure:
_rels
package
lib
contentFiles
+- any
+- netstandard2.0
+- LICENSE
content
+- LICENSE
Could I, for instance, add it to a separate folder inside the package, other than content
?
The recommended way of packing a licence file with the package is
<PropertyGroup>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
</PropertyGroup>
<ItemGroup>
<None Include="LICENSE.txt" Pack="true" PackagePath="$(PackageLicenseFile)"/>
</ItemGroup>
But also there now is PackageLicenseExpression
which can be used as an alternative to license files / URLs as you have mentioned in your comment.
See NuGet's wiki entry Packaging License within the nupkg for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With