NuGet 无法使用 XmlnsDefinitionAttribute 从程序集中提取元数据
我正在尝试将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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
解决方案是将平台设置为AnyCPU<进行编译/强>。
A solution is to compile with Platform set to AnyCPU.
我也面临这个问题 - 在 TFS Build-Agent 中构建它。
我对此问题有两个“解决方案”,但都有各自的“问题”:
1.)激活“复制本地”以引用“System.Windows”。
2 .) 将 Silverlight System.Windows.dll 复制到 nuget.exe 路径中 - 对于 TFS (2017) Build Agent,在 64 位系统上(这 - 与之前的一些评论相反 - 确实工作):
那么 - 你们会选择哪种解决方案?
更新:现在我将使用解决方案#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".
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):
So - which solution would you guys choose?
Update: For now I will use solution #1, as it sounds less dangerous.