NUget:无法从 obj 中提取元数据

NUget: Unable to extract metadata from obj

使用 NuGet 2.8.3 从 Visual Studio 2013 Update 4 构建 nuget 包时,我收到以下警告:

EXEC : warning : Unable to extract metadata from 'MyAssembly.dll'. [D:\Development\MyAssembly\MyAssembly.csproj]
EXEC : warning : Description was not specified. Using 'Description'. [D:\Development\MyAssembly\MyAssembly.csproj]
EXEC : warning : Author was not specified. Using 'GDo'. [D:\Development\MyAssembly\MyAssembly.csproj]
EXEC : warning : Unable to extract metadata from 'MyAssembly.dll'. [D:\Development\MyAssembly\MyAssembly.csproj]
EXEC : warning : Description was not specified. Using 'Description'. [D:\Development\MyAssembly\MyAssembly.csproj]
EXEC : warning : Author was not specified. Using 'GDo'. [D:\Development\MyAssembly\MyAssembly.csproj]

生成的 nuget 包被命名为 MyAssembly.1.0.0.0.nupkg 而我期待的是 1.4.4

尽管有以下AssemblyInfo.cs

using System.Reflection;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MyAssembly")]
[assembly: AssemblyDescription("components and factory")]
[assembly: AssemblyVersion("1.0.0.0")] // change this when the interface changes
[assembly: AssemblyInformationalVersion("1.4.4")] // used by the NuGet pack implementation

我正在使用以下 post-build 事件:

"$(DEVTOOLS)\NuGet\NuGet.exe" pack "$(ProjectPath)" -symbols -IncludeReferencedProjects -Properties "Configuration=$(Configuration);Platform=$(Platform);OutputPath=Obj$(Configuration)" -NonInteractive -MinClientVersion 2.5

我们在所有项目上使用此 post-build 事件,它们都在 Visual Studio 和 TFS CI 构建服务器上生成正确的包。

当我从这个特定项目的命令行运行 msbuild 时,我可以看到 nuget 命令被调用为:

"D:\DevTools\NuGet\NuGet.exe" pack "D:\Development\MyAssembly\MyAssembly.csproj" -symbols -IncludeReferencedProjects -Properties "Configuration=Debug;Platform=AnyCPU;OutputPath=Obj\Debug" -NonInteractive -MinClientVersion 2.5
Attempting to build package from 'MyAssembly\MyAssembly.csproj'.
Packing files from 'D:\Development\MyAssembly\Obj\Debug'.
EXEC : warning : Unable to extract metadata from 'MyAssembly.dll' [D:\Development\MyAssembly\MyAssembly.csproj]
File from dependency is not changed. File 'native.dll' is not added.
Found packages.config. Using packages listed as dependencies
EXEC : warning : Description was not specified. Using 'Description'. [D:\Development\MyAssembly\MyAssembly.csproj]
EXEC : warning : Author was not specified. Using 'GDo'. [D:\Development\MyAssembly\MyAssembly.csproj]
Successfully created package 'D:\Development\MyAssembly\bin\Debug\MyAssembly.1.0.0.0.nupkg'.

当我更改此命令以引用 bin 文件夹而不是 obj 文件夹时:

"D:\DevTools\NuGet\NuGet.exe" pack "D:\Development\MyAssembly\MyAssembly.csproj" -symbols -IncludeReferencedProjects -Properties "Configuration=Debug;Platform=AnyCPU;OutputPath=**bin**\Debug" -NonInteractive -MinClientVersion 2.5

我得到了预期的行为,包按预期构建并具有正确的版本等:

Attempting to build package from 'MyAssembly.csproj'.
Packing files from 'D:\Development\MyAssembly\bin\Debug'.
File from dependency is not changed. File 'native.dll' is not added.
Found packages.config. Using packages listed as dependencies
Successfully created package 'D:\Development\MyAssembly\MyAssembly.1.4.4.nupkg'.

但这很奇怪。 post 构建事件适用于所有其他项目,例如

  "D:\DevTools\NuGet\NuGet.exe" pack "D:\Development\MyOtherAssembly\MyOtherAssembly.csproj" -symbols -IncludeReferencedP
  rojects -Properties "Configuration=Debug;Platform=AnyCPU;OutputPath=Obj\Debug" -NonInteractive -MinClientVersion 2.5
  Attempting to build package from 'MyOtherAssembly.csproj'.
  Packing files from 'D:\Development\MyOtherAssembly\Obj\Debug'.
  Found packages.config. Using packages listed as dependencies
  Successfully created package 'D:\Development\MyOtherAssembly\bin\Debug\MyOtherAssembly.1.4.1.nupkg'.

更奇怪的是,损坏的项目的构建在具有相同源代码的另一位开发人员的机器上工作得很好。手动运行 msbuild 确实会产生相同的错误,但生成的包具有正确的版本。 (是的,我尝试从 TFS 获取新的源代码树,但无济于事) 有人可以解释可能是什么原因吗?

更新:签入后,我们的 TFS 服务器现在有相同的构建问题并且仅生成 nuget 包版本 1.0.0.0。

打包失败的原因被nuget隐藏了。当我们使用开关 -Verbosity detailed 手动构建包时 我们从 nuget 收到了完整的堆栈跟踪,在依赖的 dll 上有一个 FileNotFoundException,在我们的例子中是 log4net。事实上,这个dll并没有复制到obj文件夹。

我们在 类 之一中将其缩小到以下属性:

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

这导致 nuget 在开始读取程序集元数据时寻找 log4net.dll。我们通过将 log4net dll 复制到 obj 文件夹来验证这一点。 (构建成功)然后我们删除了这个属性,这完全解决了问题。

我注意到了这种行为,因为 nuget 没有从我的程序集中获取版本号。上面的消息仅由 nuget 2.8.6 显示,但我使用的是 3.5 and/or 4.0,它不报告警告但也无法提取元数据。

我的问题是由于我有多个版本的 nuget 并重命名可执行文件以匹配版本。我将 2.8.6 版本重命名为 nuget.2.8.6.exe,将 3.5 版本重命名为 nuget.3.5.0.exe,将 4.0 版本重命名为 nuget.4.0.0.exe。 3.5 的 fuslogvw 输出显示它找不到文件 nuget3.5.0.exe.config,这似乎是导致问题的原因。

我将可执行文件重命名回 nuget.exe 后一切又开始工作了。