NuGet 无法使用 XmlnsDefinitionAttribute 从程序集中提取元数据

发布于 2024-12-09 11:47:56 字数 2962 浏览 0 评论 0原文

我正在尝试将 XmlnsDefinitionAttributes 添加到我的程序集中。我使用 TeamCity 来管理我的项目。我的构建配置中有一个 NuGet Package Pack 步骤。

这是失败的构建日志的相关部分。

[16:42:08]: Starting: C:\Windows\system32\cmd.exe /c C:\BuildAgent\tools\NuGet.CommandLine.1.5.20905.5.nupkg\tools\NuGet.exe pack C:\BuildAgent\work\5f0e65f22ca1527\MyProject\MyProject.csproj -OutputDirectory \\server\Packages -BasePath C:\BuildAgent\work\5f0e65f22ca1527 -Verbose -Version 1.0.97.1034 -Symbols -Properties Configuration=Release
[16:42:08]: in directory: C:\BuildAgent\work\5f0e65f22ca1527
[16:42:08]: Attempting to build package from 'MyProject.csproj'.
[16:42:09]: Packing files from 'C:\BuildAgent\work\5f0e65f22ca1527\MyProject\Bin\Release'.
[16:42:09]: WARNING: Unable to extract metadata from 'MyProject.dll'.
[16:42:09]: Using 'MyProject.nuspec' for metadata.
[16:42:09]: The replacement token 'title' has no value.
[16:42:09]: Process exited with code 1

成功构建的同一部分如下所示。

[16:42:54]: Starting: C:\Windows\system32\cmd.exe /c C:\BuildAgent\tool\NuGet.CommandLine.1.5.20905.5.nupkg\tools\NuGet.exe pack C:\BuildAgent\work\5f0e65f22ca1527\MyProject\MyProject.csproj -OutputDirectory \\server\Packages -BasePath C:\BuildAgent\work\5f0e65f22ca1527 -Verbose -Version 1.0.98.1035 -Symbols -Properties Configuration=Release
[16:42:54]: in directory: C:\BuildAgent\work\5f0e65f22ca1527
[16:42:54]: Attempting to build package from 'MyProject.csproj'.
[16:42:54]: Packing files from 'C:\BuildAgent\work\5f0e65f22ca1527\MyProject\Bin\Release'.
[16:42:54]: Using 'MyProject.nuspec' for metadata.

此时它输出所有设置。

我的 XmlnsDefinitionAttribute 在 AssemblyInfo.cs 中定义如下

[assembly: XmlnsDefinition("http://schemas.company.com/myproject", "MyProject")]

关于我做错了什么有什么想法吗?

编辑

这是我的完整 AssemblyInfo.cs

using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Markup;

[assembly: AssemblyTitle("MyProject")]
[assembly: AssemblyDescription("MyProject Description")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("MyProject")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("23774732-4f22-4366-a150-03745e93111b")]

[assembly: AssemblyVersion("1.5.2")]
[assembly: AssemblyFileVersion("1.5.2")]

[assembly: XmlnsDefinition("http://schemas.company.com/myproject", "MyProject")]
[assembly: XmlnsDefinition("http://schemas.company.com/myproject", "MyProject.Namespace1")]
[assembly: XmlnsDefinition("http://schemas.company.com/myproject/newschema", "MyProject.NewSchema")]
[assembly: XmlnsDefinition("http://schemas.company.com/myproject/newschema", "MyProject.NewSchema.Namespace1")]

编辑 2

我在本地安装了 NuGet,但遇到了相同的错误。 TeamCity 似乎没有任何效果。

I am trying to add XmlnsDefinitionAttributes to my assembly. I use TeamCity to manage my projects. There is a NuGet Package Pack step in my build configuration.

Here is the relevant section of a failed build log.

[16:42:08]: Starting: C:\Windows\system32\cmd.exe /c C:\BuildAgent\tools\NuGet.CommandLine.1.5.20905.5.nupkg\tools\NuGet.exe pack C:\BuildAgent\work\5f0e65f22ca1527\MyProject\MyProject.csproj -OutputDirectory \\server\Packages -BasePath C:\BuildAgent\work\5f0e65f22ca1527 -Verbose -Version 1.0.97.1034 -Symbols -Properties Configuration=Release
[16:42:08]: in directory: C:\BuildAgent\work\5f0e65f22ca1527
[16:42:08]: Attempting to build package from 'MyProject.csproj'.
[16:42:09]: Packing files from 'C:\BuildAgent\work\5f0e65f22ca1527\MyProject\Bin\Release'.
[16:42:09]: WARNING: Unable to extract metadata from 'MyProject.dll'.
[16:42:09]: Using 'MyProject.nuspec' for metadata.
[16:42:09]: The replacement token 'title' has no value.
[16:42:09]: Process exited with code 1

The same section for a successful build looks like this.

[16:42:54]: Starting: C:\Windows\system32\cmd.exe /c C:\BuildAgent\tool\NuGet.CommandLine.1.5.20905.5.nupkg\tools\NuGet.exe pack C:\BuildAgent\work\5f0e65f22ca1527\MyProject\MyProject.csproj -OutputDirectory \\server\Packages -BasePath C:\BuildAgent\work\5f0e65f22ca1527 -Verbose -Version 1.0.98.1035 -Symbols -Properties Configuration=Release
[16:42:54]: in directory: C:\BuildAgent\work\5f0e65f22ca1527
[16:42:54]: Attempting to build package from 'MyProject.csproj'.
[16:42:54]: Packing files from 'C:\BuildAgent\work\5f0e65f22ca1527\MyProject\Bin\Release'.
[16:42:54]: Using 'MyProject.nuspec' for metadata.

At this point it outputs all of the settings.

My XmlnsDefinitionAttribute is defined in AssemblyInfo.cs as follows

[assembly: XmlnsDefinition("http://schemas.company.com/myproject", "MyProject")]

Any ideas as to what I am doing wrong?

Edit

Here is my full AssemblyInfo.cs

using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Markup;

[assembly: AssemblyTitle("MyProject")]
[assembly: AssemblyDescription("MyProject Description")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("MyProject")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("23774732-4f22-4366-a150-03745e93111b")]

[assembly: AssemblyVersion("1.5.2")]
[assembly: AssemblyFileVersion("1.5.2")]

[assembly: XmlnsDefinition("http://schemas.company.com/myproject", "MyProject")]
[assembly: XmlnsDefinition("http://schemas.company.com/myproject", "MyProject.Namespace1")]
[assembly: XmlnsDefinition("http://schemas.company.com/myproject/newschema", "MyProject.NewSchema")]
[assembly: XmlnsDefinition("http://schemas.company.com/myproject/newschema", "MyProject.NewSchema.Namespace1")]

Edit 2

I installed NuGet locally and I am getting the same error. TeamCity does not appear to have any effect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千紇 2024-12-16 11:47:56

Nuget将尝试从程序集中获取元数据,并通过执行do,它将加载所有程序集属性。

出现此问题的原因是 XmlnsDefinition 在 System.Windows 程序集 (System.Windows.dll) 中定义,并且该特定程序集通常不会输出到构建文件夹,因此 NuGet 无法找到它并引发异常(只有从代码运行 NuGet 才能发现异常!)

我发现绕过此问题的最佳方法是确保运行 NuGet.exe 时 System.Windows.dll 文件与主程序集位于同一文件夹中

Nuget will try to get metadata from the assembly, and by doing do, it will load all assembly attributes.

This issue occurs because XmlnsDefinition is defined in System.Windows assembly (System.Windows.dll), and that particular assembly is normally not outputed to the build folder, so NuGet can't find it and throws an exception (you can only spot the exception if you run NuGet from code!)

Best way I found to bypass this issue is to make sure the System.Windows.dll file is in the same folder as the main assembly when you run NuGet.exe

网名女生简单气质 2024-12-16 11:47:56

解决方案是将平台设置为AnyCPU<进行编译/强>。

A solution is to compile with Platform set to AnyCPU.

泛泛之交 2024-12-16 11:47:56

我也面临这个问题 - 在 TFS Build-Agent 中构建它。

我对此问题有两个“解决方案”,但都有各自的“问题”:

1.)激活“复制本地”以引用“System.Windows”。

  • 这种方法的问题是......System.Windows.dll可能包含在XAP中,而通常情况下不包含在XAP中。这听起来很危险......
    • (尽管 - 有人可能会说“XmlnsDefinitionAttribute”永远不会在“App”程序集中使用,而在库 DLL 中使用......所以这个“问题”没有实际意义?

2 .) 将 Silverlight System.Windows.dll 复制到 nuget.exe 路径中 - 对于 TFS (2017) Build Agent,在 64 位系统上(这 - 与之前的一些评论相反 - 确实工作):

copy "c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\System.Windows.dll" "C:\agent\externals\nuget"
  • 问题这里可能是:
    • Silverlight SDK 更新了吗? (再复印一次?)
    • 非 Silverlight 版本? (NuGet 会选择错误的 System.Windows.dll 吗?)

那么 - 你们会选择哪种解决方案?

更新:现在我将使用解决方案#1,因为它听起来不太危险。

I am facing this problem as well - building it in TFS Build-Agent.

I have 2 "solutions" to this problem, but both have their own "problems":

1.) Activate "Copy Local" for reference "System.Windows".

  • the problem with this approach....System.Windows.dll might be included in XAP, which it normally isn't. This sounds dangerous....
    • (although - one could argue that "XmlnsDefinitionAttribute" will never be used in the "App" Assembly, but only in Library DLLs....so this "problem" is moot?

2.) Copy the Silverlight System.Windows.dll into the nuget.exe path - for TFS (2017) Build Agent, on 64bit systems (which - contrary to some earlier comments - does work):

copy "c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\System.Windows.dll" "C:\agent\externals\nuget"
  • the problem here could be:
    • Silverlight SDK Updates? (do the copy again?)
    • Non-Silverlight Builds? (would NuGet pick up the wrong System.Windows.dll?)

So - which solution would you guys choose?

Update: For now I will use solution #1, as it sounds less dangerous.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文