Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 544
Alex 75 Avatar asked Aug 27 '19 20:08

Alex 75


People also ask

Are NuGet packages licensed?

Fortunately, many NuGet packages use the exact same license agreement. This means that, if you can get approval for one type of license (ex. "MIT License Agreement"), then all other packages with that license would be acceptable.


1 Answers

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="LICENSE.txt"/>
    </ItemGroup>

Using PackageLicenseExpression:

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

For more details, see

like image 80
M.Hassan Avatar answered Sep 19 '22 13:09

M.Hassan