Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core/Standard .csproj file, embedding license file without it being added to a project using the package?

Tags:

.net-core

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?

like image 347
Lasse V. Karlsen Avatar asked Nov 26 '18 19:11

Lasse V. Karlsen


1 Answers

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.

like image 200
Martin Ullrich Avatar answered Oct 05 '22 08:10

Martin Ullrich