我不记得为什么,但我放弃了使用 <nunit2> 任务,我一直在愉快地使用 <exec> 任务和 nunit-console.exe。如果有帮助,这是我运行 NUnit 和 FxCop 的测试目标。请注意,如果可执行文件不在 Windows 路径中,它会跳过它们。
<target name="test" description="Run unit tests" depends="build">
<property name="windows-path" value="${string::to-lower(environment::get-variable('PATH'))}"/>
<property name="nunit-in-path"
value="${string::contains(windows-path, 'nunit')}"/>
<echo message="Tests skipped because no NUnit folder was found in the Windows path."
unless="${nunit-in-path}"/>
<exec program="nunit-console.exe" if="${nunit-in-path}">
<arg file="../MyProject/MyProjectTest.nunit"/>
</exec>
<property name="fxcop-in-path"
value="${string::contains(windows-path, 'fxcop')}"/>
<echo message="FxCop skipped because no FxCop folder was found in the Windows path."
unless="${fxcop-in-path}"/>
<fxcop projectFile="../MyProject/MyProject.fxcop" directOutputToConsole="true"
failOnAnalysisError="true" if="${fxcop-in-path}"/>
</target>