我在使用MSBuild脚本时遇到了一些关于项目组范围的问题。基本上,我想要创建两个不同的目标 - 让我们称它们为
单元测试和集成测试的两个不同目标都依赖于构建目标,并从那里获取所有已编译的程序集的项目组,但由于
我看到了这些帖子(链接)(链接),但它们只是确认了我的担忧,并建议
以下是我目前的代码:
RunUnitTests
和RunIntegrationTests
- 生成一个名为TestAssemblies
的项目组,然后调用RunTests
,该目标使用TestAssemblies
来确定从哪些程序集运行测试。单元测试和集成测试的两个不同目标都依赖于构建目标,并从那里获取所有已编译的程序集的项目组,但由于
RunTests
目标将从不同的位置调用,因此它实际上不能依赖于其中任何一个。因此,我需要以某种方式将项目组传递给通用的测试运行器目标。然而,这似乎是不可能的,因为在目标中更改项目组似乎仅适用于该目标内部。我看到了这些帖子(链接)(链接),但它们只是确认了我的担忧,并建议
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>
有没有其他解决方案,或者我必须完全重构我的构建脚本?