简体   繁体   English

在预构建任务中更新AssemblyVersion会导致测试失败

[英]Updating AssemblyVersion in pre-build task causes test failure

We have a simple task that, before compiling, makes all of our AssemblyInfo.cs files editable, then updates 我们有一个简单的任务,在编译之前,使我们所有的AssemblyInfo.cs文件都可编辑,然后进行更新

[assembly: AssemblyVersion("1.0.0.0")] [assembly:AssemblyVersion(“ 1.0.0.0”)]

to

[assembly: AssemblyVersion("1.0.0. <SourceGetVersion> ")] [assembly:AssemblyVersion(“ 1.0.0。 <SourceGetVersion> ”)]

All of our assemblies are signed using the same key. 我们所有的程序集都使用相同的密钥签名。

This kind of thing is probably fairly standard, and it works just fine, except that it causes test failures. 这种事情可能是相当标准的,并且工作正常,只是会导致测试失败。

The failures look like this: 失败看起来像这样:

Test method Namespace.Tests.MessageTest.TestMethod threw exception: System.IO.FileLoadException: Could not load file or assembly 'Namespace.BusinessLayer.BusinessComponent.Documents, Version=1.0.0.4344, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx' or one of its dependencies. 测试方法Namespace.Tests.MessageTest.TestMethod引发异常:System.IO.FileLoadException:无法加载文件或程序集“ Namespace.BusinessLayer.BusinessComponent.Documents,Version = 1.0.0.4344,Culture = neutral,PublicKeyToken = xxxxxxxxxxxxxxxx”或以下之一它的依赖性。 The located assembly's manifest definition does not match the assembly reference. 找到的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (来自HRESULT的异常:0x80131040)

So, I turned on the logging that was suggested, and get this: 因此,我打开了建议的日志记录,并得到以下信息:

W, 3964, 90, 2010/12/07, 09:57:43.059, TFSBUILD\\QTAgent32.exe, Getting custom attributes for type System.Reflection.RuntimeMethodInfo threw exception (will ignore and use the reflection way): System.IO.FileLoadException: Could not load file or assembly 'Namespace.BusinessLayer.BusinessEntity, Version=1.0.0.4344, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx' or one of its dependencies. W,3964,90,2010/12/07,09:57:43.059,TFSBUILD \\ QTAgent32.exe,获取类型System.Reflection.RuntimeMethodInfo的自定义属性引发异常(将忽略并使用反射方式):System.IO。 FileLoadException:无法加载文件或程序集'Namespace.BusinessLayer.BusinessEntity,Version = 1.0.0.4344,Culture = neutral,PublicKeyToken = xxxxxxxxxxxxxxxx'或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference. 找到的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) File name: 'Namespace.BusinessLayer.BusinessEntity, Version=1.0.0.4344, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx' at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs) at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit) at System.Reflection.RuntimeMethodInfo.GetCustomAttributes(Boolean inherit) at Microsoft.VisualStudio.TestTools.Common.ReflectHelper.GetAttributes(MemberInf (来自HRESULT的异常:0x80131040)文件名:'Namespace.BusinessLayer.BusinessEntity,Version = 1.0.0.4344,Culture = neutral,PublicKeyToken = xxxxxxxxxxxxxxxx'位于System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule,IRuntimeMethodInfo pCtor,Byte ** ppBlob ,位于System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule模块,IRuntimeMethodInfo ctor,IntPtr&blob,IntPtr blobEnd,Int32&namedArgs)的System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule装饰模数,Int32, ,在Microsoft.VisualStudio.TestTools上,在System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo方法,RuntimeType caType,布尔值继承)处为System.Reflection.RuntimeMethodInfo.GetCustomAttributes(布尔值继承)处的RuntimeType attributeFilterType,布尔值mustBeInheritable,IList派生属性,布尔值isDecoratedTargetSecurityTransparent)。 Common.ReflectHelper.GetAttributes(MemberInf o info, Boolean bInherit) o info,布尔值bInherit)

=== Pre-bind state information === LOG: User = domain\\tfsbuildAccount LOG: DisplayName = Namespace.BusinessLayer.BusinessEntity, Version=1.0.0.4344, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx (Fully-specified) LOG: Appbase = file:///D:/Builds/4/10/TestResults/tfsbuildAccount-TFSBUILD 2010-12-07 09_56_54_x86_Debug/Out LOG: Initial PrivatePath = NULL Calling assembly : Namespace.BusinessLayer.BusinessComponent.Edi.Tests, Version=1.0.0.4344, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx. ===绑定前状态信息===日志:用户= domain \\ tfsbuildAccount日志:DisplayName = Namespace.BusinessLayer.BusinessEntity,Version = 1.0.0.4344,Culture = neutral,PublicKeyToken = xxxxxxxxxxxxxxxx(完全指定)LOG:Appbase =文件:/// D:/ Builds / 4/10 / TestResults / tfsbuildAccount-TFSBUILD 2010-12-07 09_56_54_x86_Debug / Out日志:初始PrivatePath = NULL调用程序集:Namespace.BusinessLayer.BusinessComponent.Edi.Tests,Version = 1.0。 0.4344,文化=中性,PublicKeyToken = xxxxxxxxxxxxxxxx。 === LOG: This bind starts in default load context. === LOG:此绑定在默认加载上下文中启动。 LOG: Using application configuration file: D:\\Builds\\4\\10\\TestResults\\tfsbuildAccount-TFSBUILD 2010-12-07 09_56_54_x86_Debug\\Out\\Namespace.BusinessLayer.BusinessComponent.Edi.Tests.DLL.config LOG: Using host configuration file: LOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\config\\machine.config. 日志:使用应用程序配置文件:D:\\ Builds \\ 4 \\ 10 \\ TestResults \\ tfsbuildAccount-TFSBUILD 2010-12-07 09_56_54_x86_Debug \\ Out \\ Namespace.BusinessLayer.BusinessComponent.Edi.Tests.DLL.config日志:使用主机配置文件:日志:使用C:\\ Windows \\ Microsoft.NET \\ Framework \\ v4.0.30319 \\ config \\ machine.config中的计算机配置文件。 LOG: Post-policy reference: Namespace.BusinessLayer.BusinessEntity, Version=1.0.0.4344, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx LOG: Attempting download of new URL file:///D:/Builds/4/10/TestResults/tfsbuildAccount-TFSBUILD 2010-12-07 09_56_54_x86_Debug/Out/Namespace.BusinessLayer.BusinessEntity.DLL. 日志:政策后参考:Namespace.BusinessLayer.BusinessEntity,版本= 1.0.0.4344,文化=中性,PublicKeyToken = xxxxxxxxxxxxxxxx日志:尝试下载新的URL文件:/// D:/ Builds / 4/10 / TestResults / tfsbuildAccount -TFSBUILD 2010-12-07 09_56_54_x86_Debug / Out / Namespace.BusinessLayer.BusinessEntity.DLL。 WRN: Comparing the assembly name resulted in the mismatch: Revision Number ERR: Failed to complete setup of assembly (hr = 0x80131040). WRN:比较程序集名称会导致不匹配: 修订号 ERR:无法完成程序集的设置(hr = 0x80131040)。 Probing terminated. 探测终止。

Now, I may have mixed up the assemblies posting this, but it's the same pattern for all the tests. 现在,我可能将发布此代码的程序集弄混了,但是所有测试的模式都是相同的。 Mind you, the public keys are all the same, and I can see that all of the revision numbers are the same. 请注意,公钥都是相同的,我可以看到所有修订版本号都相同。

What are we doing wrong? 我们做错了什么?

Try changing the reference assebly to be not version specific. 尝试将参考组件更改为非特定于版本。 "Secific Version = False" in the properties tab for the assembly. 程序集的属性选项卡中的“ Secific Version = False”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM