在构建服务器上运行 Moles - 有什么想法可以跳过代码生成吗?
运行 Moles 0.94 是为了消除 3rdparty 程序集中的某些类型,否则这些类型将很难测试。在本地运行良好,测试通过并且解决方案编译良好。第一次编译确实需要相当长的时间,因为它会生成摩尔程序集(将它们放入名为 \molesassemblies 的子文件夹中),但随后的时间要快得多 - 摩尔输出以下内容:
Moles : info : compilation : assembly metadata hash unchanged, skipping code generation
问题是,我如何模仿这种行为在每次重新同步(拆除)工作区的构建服务器上?这可能吗? (当前使用 TFS 2010 作为构建服务器)。
我天真地尝试检查名为 \molesassemblies\ 的项目子文件夹的内容,希望当 msbuild 在解决方案编译期间调用 Moles 框架时,它会识别出程序集已经存在,从而跳过代码生成。然而,仅仅这样做似乎并不起作用。该框架似乎认为它需要重新生成代码,然后抱怨签入的程序集是只读的:
00:00:00.00> moles
Moles : info : metadata : ignoring reference D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\MolesAssemblies\3rdparty.assembly.moles.dll
Moles : info : metadata : loading D:\Builds\49\mycompany\BUILD-NAME\Sources\3rdPartyBinaries\3rdparty\3rdparty.assembly.dll
Moles : info : compilation : output assembly name: 3rdparty.assembly.moles
Moles : info : code : found 2912 types
Moles : info : code : visibility: exported or assembly(3rdparty.assembly.moles)
00:00:03.10> code generation
Moles : info : code : generating code at D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\obj\Release\Moles\sk\m.g.cs
00:00:03.44> stubs generation
Moles : info : code : generated 2274 stub types
00:00:08.32> moles generation
Moles : info : code : generated 2638 mole types
00:00:45.13> compiling
Moles : error : compilation : D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\MolesAssemblies\3rdparty.assembly.moles.dll readonly [D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\TestHelpers.csproj]
00:02:27.44> moles generator 1 errors, 0 warnings
C:\Program Files\Microsoft Moles\bin\Microsoft.Moles.targets(79,5): error MSB3073: The command ""C:\Program Files\Microsoft Moles\bin\moles.exe" @D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\obj\Release\Moles\moles.args" exited with code -1009. [D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\TestHelpers.csproj]
Result: error while copying output (-1009 - 0xfffffc0f)
MolesAssemblies:
3rdparty.assembly.moles ignored because already referenced from other location
Done Building Project "D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\TestHelpers.csproj" (default targets) -- FAILED.
任何有关我可以采取哪些措施来使其工作的指导将不胜感激。
谢谢。
Running Moles 0.94 in order to stub out certain types in 3rdparty assemblies which would be otherwise hard to test. Works great locally, tests pass and the solution compiles fine. The first time it compiles it does take quite a while because it generates the mole assemblies (puts them into a subfolder called \molesassemblies) but subsequent times it is much faster - moles outputs the following:
Moles : info : compilation : assembly metadata hash unchanged, skipping code generation
The question is, how do I mimic this behaviour on a build server which re-syncs (tears down) the workspace every time? Is this even possible? (Currently using TFS 2010 as a build server).
I naively tried to check in the contents of the project subfolder called \molesassemblies\ hoping that when msbuild invokes the moles framework during solution compilation it would recognise the assemblies are already there and thereby skip code generation. However, just doing that didnt seem to work. The framework seemed to think it needed to regenerate the code, and then complained that the checked in assemblies were read-only:
00:00:00.00> moles
Moles : info : metadata : ignoring reference D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\MolesAssemblies\3rdparty.assembly.moles.dll
Moles : info : metadata : loading D:\Builds\49\mycompany\BUILD-NAME\Sources\3rdPartyBinaries\3rdparty\3rdparty.assembly.dll
Moles : info : compilation : output assembly name: 3rdparty.assembly.moles
Moles : info : code : found 2912 types
Moles : info : code : visibility: exported or assembly(3rdparty.assembly.moles)
00:00:03.10> code generation
Moles : info : code : generating code at D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\obj\Release\Moles\sk\m.g.cs
00:00:03.44> stubs generation
Moles : info : code : generated 2274 stub types
00:00:08.32> moles generation
Moles : info : code : generated 2638 mole types
00:00:45.13> compiling
Moles : error : compilation : D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\MolesAssemblies\3rdparty.assembly.moles.dll readonly [D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\TestHelpers.csproj]
00:02:27.44> moles generator 1 errors, 0 warnings
C:\Program Files\Microsoft Moles\bin\Microsoft.Moles.targets(79,5): error MSB3073: The command ""C:\Program Files\Microsoft Moles\bin\moles.exe" @D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\obj\Release\Moles\moles.args" exited with code -1009. [D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\TestHelpers.csproj]
Result: error while copying output (-1009 - 0xfffffc0f)
MolesAssemblies:
3rdparty.assembly.moles ignored because already referenced from other location
Done Building Project "D:\Builds\49\mycompany\BUILD-NAME\Sources\Products\Product\Tests\TestHelpers\TestHelpers.csproj" (default targets) -- FAILED.
Any guidance on what I could do to get this working would be appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是这里没有一个很好的答案。 Moles 程序集过去被签入源代码管理和测试项目的一部分,然后 Moles 团队更改了此功能,因为每次 API 更改时,人们都必须签出并签入 DLL,但没有人真正喜欢这样做,因为它既麻烦又烦人。现在,只需签入 Mole 内容的 XML 清单。鉴于此,我可以想到几个选项:
1- 更改 TFS 构建定义,通过在构建之间设置“清理工作空间”字段来保留工作空间。将“进程”选项卡设置为“无”或“输出”,看看这是否有帮助
2- 将 Moles 程序集托管在源代码控制之外的某个位置,并将它们作为预构建任务复制到有问题的测试项目中。
Unfortunately there's not a great answer here. Moles assemblies used to be checked into source control and part of a test project, then the Moles team changed this functionality since everytime an API changed people had to check out and in the DLLs and no one really like that as it was cumbersome and annoying. Now just the XML manifest of what to Mole is checked in. Given this, you have a couple of options that I can think of:
1- Change your TFS Build definition to keep your workspace around between builds by setting the Clean Workspace field on the Process tab to None or Outputs and see if that helps
2- Host your Moles assemblies somewhere out of source control and copy them in as a pre-build task on the offending Test project.