【发布时间】:2010-12-09 15:15:00
【问题描述】:
我们有一个简单的任务,在编译之前,让我们所有的 AssemblyInfo.cs 文件都可编辑,然后更新
[程序集:AssemblyVersion("1.0.0.0")]
到
[程序集:AssemblyVersion("1.0.0.<SourceGetVersion>")]
我们所有的程序集都使用相同的密钥进行签名。
这种事情可能是相当标准的,它工作得很好,只是它会导致测试失败。
故障如下所示:
测试方法 命名空间.Tests.MessageTest.TestMethod 抛出异常: System.IO.FileLoadException:不能 加载文件或程序集 '命名空间.BusinessLayer.BusinessComponent.Documents, 版本=1.0.0.4344,文化=中性, PublicKeyToken=xxxxxxxxxxxxxxxxxx' 或 它的依赖项之一。位于 程序集的清单定义确实 与程序集引用不匹配。 (HRESULT 异常:0x80131040)
所以,我打开了建议的日志记录,得到了这个:
W, 3964, 90, 2010/12/07, 09:57:43.059, TFSBUILD\QTAgent32.exe,获取 类型的自定义属性 System.Reflection.RuntimeMethodInfo 抛出异常(将忽略并使用 反射方式): System.IO.FileLoadException:不能 加载文件或程序集 '命名空间.BusinessLayer.BusinessEntity, 版本=1.0.0.4344,文化=中性, PublicKeyToken=xxxxxxxxxxxxxxxxxx' 或 它的依赖项之一。位于 程序集的清单定义确实 与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040) 文件名: '命名空间.BusinessLayer.BusinessEntity, 版本=1.0.0.4344,文化=中性, PublicKeyToken=xxxxxxxxxxxxxxxxxx' 在 System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule,IRuntimeMethodInfo pCtor, 字节** ppBlob, 字节* pEndBlob, Int32* pcNamedArgs)在 System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule 模块,IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& 命名Args)在 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule 装饰模块,Int32 装饰元数据令牌,Int32 pcaCount,运行时类型 属性过滤器类型,布尔值 mustBeInheritable, IList 派生属性,布尔值 isDecoratedTargetSecurityTransparent) 在 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo 方法,RuntimeType caType,布尔值 继承)在 System.Reflection.RuntimeMethodInfo.GetCustomAttributes(布尔值 继承)在 Microsoft.VisualStudio.TestTools.Common.ReflectHelper.GetAttributes(MemberInfo 信息,布尔 bInherit)
=== 预绑定状态信息 === LOG: User = domain\tfsbuildAccount 日志:显示名称 = 命名空间.BusinessLayer.BusinessEntity, 版本=1.0.0.4344,文化=中性, PublicKeyToken=xxxxxxxxxxxxxxx (完全指定)日志:Appbase = file:///D:/Builds/4/10/TestResults/tfsbuildAccount-TFSBUILD 2010-12-07 09_56_54_x86_Debug/Out 日志: 初始 PrivatePath = NULL 调用 部件 : 命名空间.BusinessLayer.BusinessComponent.Edi.Tests, 版本=1.0.0.4344,文化=中性, PublicKeyToken=xxxxxxxxxxxxxxx。 === LOG:此绑定在默认加载上下文中开始。日志:使用应用程序 配置文件: D:\Builds\4\10\TestResults\tfsbuildAccount-TFSBUILD 2010-12-07 09_56_54_x86_Debug\Out\Namespace.BusinessLayer.BusinessComponent.Edi.Tests.DLL.config LOG:使用主机配置文件: LOG:使用机器配置文件 从 C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config。 日志:政策后参考: 命名空间.BusinessLayer.BusinessEntity, 版本=1.0.0.4344,文化=中性, PublicKeyToken=xxxxxxxxxxxxxxxxxx 日志: 正在尝试下载新 URL file:///D:/Builds/4/10/TestResults/tfsbuildAccount-TFSBUILD 2010-12-07 09_56_54_x86_Debug/Out/Namespace.BusinessLayer.BusinessEntity.DLL。 警告:比较程序集名称 导致不匹配:修订 Number ERR: 未能完成设置 装配(hr = 0x80131040)。探测 终止。
现在,我可能混淆了发布此内容的程序集,但所有测试的模式都是相同的。请注意,公钥都是一样的,我可以看到所有的修订号都是一样的。
我们做错了什么?
【问题讨论】: