【问题标题】:NUget: Unable to extract metadata from objNUget:无法从 obj 中提取元数据
【发布时间】:2015-01-08 12:26:13
【问题描述】:

在使用 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

我正在使用以下构建后事件:

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

我们在所有项目上都使用此构建后事件,它们都会在 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'.

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

  "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。

【问题讨论】:

  • 您尝试过干净构建吗?您可能在以前的构建中遇到了一些问题,导致问题。
  • 是的,我做到了,试过clean,build,rebuild,release,debug,各种配置,都无济于事。

标签: visual-studio-2013 msbuild nuget


【解决方案1】:

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

我们在其中一个类中将其缩小为以下属性:

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

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

【讨论】:

  • 我刚刚遇到了同样的问题,但是在创建 Xamarin.iOS NuGet 包时,我通过手动复制 Xamarin.iOS DLL 尝试了上面的测试,但我的解决方案是标记特定程序集为 Copy Local = True
【解决方案2】:

我注意到了这种行为,因为 nuget 没有从我的程序集中获取版本号。上面的消息仅由 nuget 2.8.6 显示,但我使用的是 3.5 和/或 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 后,一切又开始工作了。

【讨论】:

    猜你喜欢
    • 2014-12-04
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 2013-04-06
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多