NuGet Packing a Nuspec: Value cannot be null or empty string. Parameter name: value

user3066571 picture user3066571 · Nov 20, 2017 · Viewed 7.1k times · Source

I'm packaging up a bunch of javascript for a website. Here's what my .nuspec looks like.

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <version>$version$</version>
    <authors>Author Person</authors>
    <owners>Company Name</owners>
    <id>PackageNameId</id>
    <title>PackageNameId</title>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description text stuff</description>
    <copyright>Company Copyright Info</copyright>
  </metadata>
  <files>
    <file src="www\**" target="" />  <!--It just packages everything in the www folder in the same directory as this .nuspec -->
  </files>
</package>

It just packages everything in that www folder. The $version$ token should be getting replaced by the NugetPackage version flag in TFS (what I'm building in).

I don't see anything called value, so I'm really at a loss for why it's throwing an error.

Here's the full error:

Attempting to build package from 'PackageName.nuspec'.

##[error]Value cannot be null or an empty string.

##[error]Parameter name: value

Answer

tessafyi picture tessafyi · Jan 12, 2018

I suspect you're getting this error running nuget pack on your nuspec file instead of your csproj file.

As I learned from this open NuGet issue, AssemblyInfo token replacement (e.g. <version>$version$</version>) only works if you're calling nuget pack on your .csproj or .vbproj file. Quoting from NuGet documentation:

Using the project file directly is necessary for token replacement because the project is the source of the token values. Token replacement does not happen if you use nuget pack with a .nuspec file.