Path 如何获取NUnit NUnit-console.exe的路径
我正在尝试制作一个Nant脚本,到目前为止它一直运行良好,但我不希望硬编码文件位置。在我必须执行nunit-console.exe之前,这一切都很好,但我似乎无法执行。到目前为止,我发现与此相关的是:Path 如何获取NUnit NUnit-console.exe的路径,path,nunit,nant,Path,Nunit,Nant,我正在尝试制作一个Nant脚本,到目前为止它一直运行良好,但我不希望硬编码文件位置。在我必须执行nunit-console.exe之前,这一切都很好,但我似乎无法执行。到目前为止,我发现与此相关的是: <target name="test"> <property name="windows-path" value="${string::to-lower(environment::get-variable('PATH'))}"/> <prope
<target name="test">
<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="${nunit-in-path}"/>
</target>
但每次都失败了,所以我想知道两件事:
string::to lower(环境::获取变量('PATH'))
实际上做什么echo%path%
,在powershell中键入$env:path
set PATH=“%PATH%;c:\Program Files\Nunit\bin”
或者在powershell中,运行:
$env:PATH+=”;c:\program files\nunit\bin'
您还可以用相关的环境变量替换c:\Program文件。。。在Powershell中,我认为它是$env:ProgramFiles
和${env:ProgramFiles(x86)}
。。。我想它可能是命令提示符中的%PROGRAMFILES%
,但我可能错了。但是,您可以键入set
,在命令提示符下获取所有变量的列表
在系统路径中设置nunit可能更像您正在尝试的操作,因为脚本在路径变量中包含nunit的任何计算机上都可以不经修改地工作。好的,我现在似乎已经得到了它,这就是我的脚本现在的样子:
<?xml version="1.0"?>
<project name="Calculator" default="execute" basedir=".">
<property name="InstallationDir" value="C:\BoolCalc" readonly="false"/>
<property name="NUnitLocation" value="${path::combine(directory::get-current-directory(), 'NUnit\bin\net-2.0\nunit-console.exe')}" readonly="false" />
<description>The build scripts for the bool calculator</description>
<target name="clean" description="Remove all previous versions and generated files"><!--This ensures that old files are deleted if they are there and does nothing if they aren't-->
<delete dir="${InstallationDir}" failonerror="false" /><!-- This deletes the directory on your computer for the previous versions, if there are any -->
<delete file="test\Calc.exe" failonerror="false" />
</target>
<target name="build" description="compiles the source code" depends="clean">
<csc target="exe" output="test\Calc.exe" >
<sources>
<include name="src\*.cs" />
</sources>
<references>
<include name="lib\nunit.framework.dll" />
</references>
</csc>
</target>
<target name="testProgram" description="Run unit tests" depends="build">
<exec program="${NUnitLocation}"
workingdir="test\"
commandline="Calc.exe /xml:TestResults.xml /nologo" />
</target>
<target name="install" depends="testProgram">
<echo message="Installing the boolean calculator to ${InstallationDir}"/>
<copy todir="${InstallationDir}" overwrite="true">
<fileset basedir="test\">
<include name="Calc.exe" />
</fileset>
</copy>
</target>
<target name="execute" depends="install">
<echo message="Executing the calculator in ${InstallationDir}"/>
<exec program="${InstallationDir}\Calc.exe" commandline="Calc.exe" />
</target>
</project>
bool计算器的构建脚本
我接受了建议,将Nunit文件填充到workingdir中,然后使用combine和get-current-directory()创建一个完整的路径,以获取其确切位置
如果你发现这个脚本有什么问题,或者有什么可以改进的地方,请告诉我。
感谢calavera解释了我的困惑(不知道我能做到),感谢Tim Robinson和Mark Simpson提供了解决方案。我通常不会为此费心-我将NUnit发行版检查到源代码管理中,然后使用构建脚本中的相对路径我同意Tim的意见。除非您的NUnit版本在已知位置签入源代码管理,否则很难确保PC上存在相同的版本,更不用说安装路径了。NUnit开发人员提供了一个包,不需要专门为此安装:)是的,但如果NUnit不在那里,我仍然会遇到麻烦。但是谢谢你解释了什么路径,我不知道。对,所以我认为在每台机器上永久设置路径会更可靠。在我以前的工作中,我经常把它作为构建机器设置的一部分。如果只有几台机器,那没什么大不了的,但是如果你有很多机器,那可能会很麻烦,在这种情况下,你会想要一些更静态的东西,比如问题的评论者所指的东西。基本上,您可以在external/nunit这样的文件夹中签入nunit二进制文件作为源代码的一部分。然后按上面所述修改路径(我描述的第二种方法)添加外部/nunit文件夹的路径。我觉得很好,假设单元测试位于calc.exe中,而不是单独的DLL,它们位于exe中,因为它们是我们编译的一堆类。