【问题标题】:NuGet pack fails with "Unable to find '@(_OutputPathItem->'%(FullPath)..."NuGet 包因“无法找到 '@(_OutputPathItem->'%(FullPath)...”而失败
【发布时间】:2023-03-24 12:30:01
【问题描述】:

我正在尝试我的第一个 NuGet 包,但遇到了一些麻烦。我有一个相当简单的项目,以及一个非常简单的 .nuspec 文件:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <description>$description$</description>
  </metadata>
</package>

当我用这个命令行运行 NuGet 包时:

NuGet.exe pack mylibrary.csproj -Verbosity detailed -Properties Configuration=Debug

我收到此错误:

NuGet.CommandLineException: Unable to find '@(_OutputPathItem->'%(FullPath)mylibrary.dll')'. Make sure the project has been built.
   at NuGet.Commands.ProjectFactory.BuildProject()
   at NuGet.Commands.ProjectFactory.CreateBuilder(String basePath)
   at NuGet.Commands.PackCommand.BuildFromProjectFile(String path)
   at NuGet.Commands.PackCommand.BuildPackage(String path)
   at NuGet.Commands.PackCommand.ExecuteCommand()
   at NuGet.Commands.Command.Execute()
   at NuGet.Program.Main(String[] args)

输出文件肯定在 bin\Debug 文件夹中,但 NuGet 显然没有找到它们。

这显然仅在 .csproj 文件的 ToolsVersion 设置为 3.5 或更低版本时才会发生。将 ToolsVersion 设置为 4.0 即可解决问题。

似乎 MSBuild 3.5 在调用 _project.GetPropertyValue("TargetPath") (ProjectFactory.cs ~296) 时返回了未扩展的属性值,其中 MSBuild 4.0 返回了扩展的属性值。

【问题讨论】:

    标签: nuget


    【解决方案1】:

    我们遇到了同样的问题。添加

    -Prop Platform=AnyCPU
    

    到命令行使它为我们工作。

    【讨论】:

    • 有什么方法可以通过 nuspec 进行这项工作,而无需从命令行中指定?
    • 我们在笔记本电脑上使用 HP 端口复制器,将系统环境变量 PLATFORM 设置为 BNB。见Why is my Platform environment variable defined as 'BNB'?
    • 在 (2.7) 的最新版本中,似乎 -Prop 现在被称为 -Properties。对我来说,一个工作示例是:nuget pack my.csproj -Properties "Platform=AnyCpu;version=1.0;configuration=Debug"
    • 再分享一个语法:-Prop Platform=x86 -Prop Configuration=Release
    【解决方案2】:

    这显然仅在 .csproj 文件的 ToolsVersion 设置为 3.5 或更低版本时才会发生。将 ToolsVersion 设置为 4.0 即可解决问题。

    我在这里为 NuGet 项目团队创建了一个问题:https://nuget.codeplex.com/workitem/4012

    【讨论】:

      【解决方案3】:

      如果程序集的 .NET Framework 版本设置为 4.0,这也可能出现相同的错误。

      【讨论】:

        猜你喜欢
        • 2011-05-17
        • 1970-01-01
        • 2013-01-18
        • 1970-01-01
        • 1970-01-01
        • 2020-10-30
        • 1970-01-01
        • 2020-05-31
        相关资源
        最近更新 更多