Search code examples
nuget

How to fix "Invalid Element 'license' in element 'metadata' on nuget pack


I am calling Nuget Pack on a nuget file that contains a "license" tag

license type="expression">MIT</license>  

nuget pack fails as a result.

I have tried downloading the latest nuget.exe and placing it into the folder, and then using "cd" to change directory and call again. Still fails.

The exact error message is

The element 'metadata' in namespace 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd' has invalid child element 'license' in namespace 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'. List of possible elements expected: 'references, frameworkAssemblies, releaseNotes, iconUrl, summary, language, copyright, developmentDependency, serviceable, description, dependencies, repository, packageTypes, contentFiles, projectUrl, licenseUrl, tags' in namespace 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'. This validation error occurred in a 'license' element.

Solution

  • Based on the zivkan's answer, I solved the problem. As he said, I was running an older version of nuget. Updating from nuget rather than downloading the binary worked. To update, run

    nuget update -self
    

    Note that you may need to be running as administrator.