【发布时间】:2011-10-07 12:37:09
【问题描述】:
我在 MSBuild 脚本中创建的项目组的范围界定方面遇到了一些问题。基本上,我想做的是有两个不同的目标——我们称它们为RunUnitTests 和RunIntegrationTests——生成一个名为TestAssemblies 的项目组,然后调用RunTests,它使用TestAssemblies 来确定哪些程序集从中运行测试。
单元测试和集成测试的两个不同目标都依赖于构建目标,并从那里获得一个包含所有已编译程序集的项目组,但由于 RunTests 目标将从不同的地方调用,它不能真正依赖在其中任何一个上。因此,我需要以某种方式将项目组传递给 common testrunner 目标。但是,这似乎是不可能的,因为对目标中的项目组的更改似乎仅限于在该目标中起作用。
我见过theseposts,但他们似乎只是证实了我的恐惧,并建议将DependsOnTarget 作为一种解决方法——这对我不起作用,因为我需要从不同的地方获取物品在不同的运行中。
这是我目前所拥有的:
<Target Name="RunAllTests" DependsOnTarget="BuildProject">
<!-- In here, items created in BuildProject are available. -->
<CallTarget Targets="RunUnitTests;RunIntegrationTests">
</Target>
<Target Name="RunUnitTests" DependsOnTarget="BuildProject">
<!-- In here, items created in BuildProject are available. -->
<!-- One of those is @(UnitTestAssemblies) -->
<CreateItem Include="@(UnitTestAssemblies)">
<Output TaskParameter="Include" ItemName="TestAssemblies" />
</CreateItem>
<CallTarget Targets="RunTests" />
</Target>
<!-- Then there's a similar target named RunIntegrationTests, which does the
same as RunUnitTests except it includes @(IntegrationTestAssemblies) -->
<Target Name="RunTests">
<!-- Here, I'd like to access @(TestAssemblies) and pass them to the NUnit
task, but they have fallen out of scope. -->
</Target>
有什么办法可以解决这个问题,还是我必须完全重组我的构建脚本?
【问题讨论】:
-
@Thomas Gerstendörfer:请使用我当前构建脚本的简化版本查看我的更新。