nuget pack命令结果错误值不能为null或空字符串.参数名称:value

jpi*_*son 4 nuget

我正在尝试按照本指南创建我的第一个nuget包.我在build子目录中生成了一个nuspec文件和一个MSBUILD目标文件,并且都包含在csrpoj的构建输出中.我现在nuget pack按照我的bin目录中的建议运行我的nuspec文件,我收到以下错误.

> nuget pack MyPackage.nuspec
Value cannot be null or an empty string.
Parameter name: value
Run Code Online (Sandbox Code Playgroud)

错误似乎很清楚,但不能为null的值不是.这是我当前的nuspec文件的示例.

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
    <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
    <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2016</copyright>
    <tags>source version tfs git</tags>

    <packageTypes>
      <packageType type="Dependency" />
    </packageTypes>
  </metadata>
  <files>
    <!-- Include everything in \build -->
    <file src="build\**"
          target="build" />
  </files>
</package>
Run Code Online (Sandbox Code Playgroud)

jpi*_*son 5

在我的项目文件上运行nuget包会产生更多有用的信息

The element 'metadata' in namespace 'http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd' has invalid child element 'packageTypes' in namespace 'http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd'. List of possible elements expected: 'references, contentFiles, dependencies, developmentDependency, frameworkAssemblies, summary, language' in namespace 'http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd'.
Run Code Online (Sandbox Code Playgroud)

添加以下命名空间后没有任何更改.

<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
Run Code Online (Sandbox Code Playgroud)

删除packageTypes elemtn导致进一步的进展.

Authors is required.
Description is required.
Run Code Online (Sandbox Code Playgroud)

填写作者和描述,只留下警告.

WARNING: 1 issue(s) found with package 'SourceVersion'.

Issue: Remove sample nuspec values.
Description: The value "Summary of changes made in this release of the package." for ReleaseNotes is a sample value and should be removed.
Solution: Replace with an appropriate value or remove and it and rebuild your package.
Run Code Online (Sandbox Code Playgroud)

填写ReleaseNotes内容,然后允许创建包而不会出错.

注意:在上面的这些更改后,直接在nuspec文件上运行nuget包仍然会给出相同的错误.但是nuget pack MyPackage.csproj现在跑步对我来说很好,这对我来说已经足够了.

  • 我遇到过同样的问题.当.nuspec文件包含变量(例如$ id $)时,您必须在.csproj中指向nuget.exe.否则nuget不知道从哪里拉变量. (2认同)