【发布时间】: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