nugetlicensing

Upload NuGet package, how to set the license?


I'm trying to upload a new NuGet package on the website.
https://www.nuget.org/packages/manage/upload

On the first attemp I received an error that says I need to specify the license.
I don't want but... ok.

So, my first attempt with a specified license failed. I read the linked documentation and I tried multiple times.
I tried with a <license> property and also including a license.txt file in the package.

These are my try with the .nuspec file and the error I receive:

<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.  

I also tried with my license.txt without success.

What I'm doing exactly is: modify the mylibrary.nuspec file contained in a generated mylibrary.nupkg adding the <license> field.
Why? Because this VS studio project generatse the package using nuget.exe mylibrary.csproj file, and it does not contains the license.
I updated nuget.exe to the latest 5.1 version, but I don't want to modify the VS solution or project.

Any idea ?


Solution

  • Edit the .csproj file. Add the following:

    Using License file:

        <PropertyGroup>
            <PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
        </PropertyGroup>
    
        <ItemGroup>
            <None Include="licenses\LICENSE.txt" Pack="true" 
    
    PackagePath=""/>
        </ItemGroup>
    
    

    Using PackageLicenseExpression:

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

    For more details, see