如何确定哪个目标正在调用我在南特的当前目标?
我正在修改 Nant 构建脚本来运行一些单元测试。 我对本地运行的测试和在团队城市运行的测试有不同的目标。
<target name="run-unit-tests">
<property name="test.executable" value="tools\nunit\nunit-console.exe"/>
<call target="do-unit-tests"/>
</target>
<target name="run-unit-tests-teamcity">
<property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/>
<call target="do-unit-tests"/>
</target>
在目标 do-unit-tests 中,我通过设置属性并调用 NCover 执行代码覆盖率运行来设置运行哪些测试程序集,如下所示:
<target name="do-unit-test">
<property name="test.assemblies" value="MyProject.dll">
<call target="do-unit-test-coverage" />
</target>
<target name="do-unit-test-coverage">
<ncover <!--snip -->
commandLineArgs="${test.args}"
<!--snip-->
</ncover>
</target>
正如您在我需要的 ncover 部分中看到的那样名为“test.args”的属性。 此属性取决于“test.assemblies”,
即:
test.args 需要在本地运行的单元测试和团队城市上的单元测试之间进行不同的设置...所以我试图弄清楚如何设置它向上。
如果我将 test.args 的属性放在属性“test.assemblies”之后的“do-unit-test”中,如果 run-unit-tests 和另一个调用 do-unit-test,则我无法指定一个 test.args用于运行单元测试 teamcity。
我一直在尝试在“do-unit-test”中做类似以下的事情:
<if test="${target::exists('run-unit-tests-teamcity')}">
<property name="test.args" value="..." />
</if>
但显然这不起作用,因为目标将始终存在。
然后我想要测试我当前的目标 do-unit-test 是否已被 run-unit-tests-teamcity 调用,
这可能吗? 我在 Nant 文档中看不到它? 由于它不存在,它要么意味着它将成为未来的一个功能,要么意味着我不理解 Nant 构建脚本中如何指定事物。
I am modifying a Nant build script to run some unit tests. I have different targets for locally run tests and tests to be run on team city.
<target name="run-unit-tests">
<property name="test.executable" value="tools\nunit\nunit-console.exe"/>
<call target="do-unit-tests"/>
</target>
<target name="run-unit-tests-teamcity">
<property name="test.executable" value="${teamcity.dotnet.nunitlauncher}"/>
<call target="do-unit-tests"/>
</target>
in the target do-unit-tests I set up which test assemblies are run by setting a property and calling for NCover to do a code coverage run as follows:
<target name="do-unit-test">
<property name="test.assemblies" value="MyProject.dll">
<call target="do-unit-test-coverage" />
</target>
<target name="do-unit-test-coverage">
<ncover <!--snip -->
commandLineArgs="${test.args}"
<!--snip-->
</ncover>
</target>
As you can see in the ncover part I need a property called "test.args". This property depends on "test.assemblies"
ie: <property name="test.args" value="${test.assemblies} <!--snip -->" />
test.args needs to be set up differently between the locally run unit test and the one on team city...so I'm trying to figure out how to set this up.
if i put the property for test.args in "do-unit-test" after the property "test.assemblies" I can't specify one test.args if do-unit-test is called by run-unit-tests and another for run-unit-tests-teamcity.
I've been trying to do something like the following in "do-unit-test":
<if test="${target::exists('run-unit-tests-teamcity')}">
<property name="test.args" value="..." />
</if>
but obviously that doesn't work because the target will always exist.
What I'd like then is to test if my current target do-unit-test has been called by run-unit-tests-teamcity
Is this possible? I can't see it in the Nant documentation? Since its not there it either means that it will be a feature in the future or that I'm not understanding how things are specified in a Nant build script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在一个目标中定义属性,并在另一个目标中使用它们的值...例如,您可以定义
Or 如果您需要它们的结构完全不同,而不仅仅是具有一些不同的值,请利用属性这一事实替换被延迟:
如果您真的、真的只需要知道您是否在 TeamCity 中运行,那么这应该会有所帮助:
You can define properties in one target, and use their values in the other... For example, you can define
Or if you need them to be structured completely differently, not just have some different values, take advantage of the fact that the property substitution is delayed:
If you really, really just need to know if you're running in TeamCity, then this should help:
我已经成功解决了这个问题。 我不知道这是否是最好的解决方案,但它是一个解决方案。
我设置了一个名为 test.type 的属性,然后使用 if 语句来确定它来自哪个目标。
I've managed to solve the problem. I don't know if it's the best solution but it is a solution.
I set a property called test.type and then use an if statement to determine which target it came from.