How to get the path to NUnit nunit-console.exe

I am trying to make a Nant script while everything is going well, but I do not want to put the files on the hard drive. This is good and good, until I have to execute nunit-console.exe, which I cannot do. What I have found so far concerns:

<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>

But this fails every time, so I would like to know a couple of things:

  • What does string::to-lower(environment::get-variable('PATH'))it really do?
  • How can I do this so that it does not break regardless of which version of windows you are using or where nunit-console.exe is located? (For example, I have NUnit in Program Files (x86) on my PC, but in Program Files on my laptop).
+3
source share
2 answers

, , , script:

<?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>

Nunit workdir, , get-current-directory(), .

- script -, , . calavera , ( , ), .

+1
  • PATH
  • , nunit-console.exe PATH , nant script. , cmd ( ) echo %PATH%, powershell $env:PATH.

, nunit-console.exe c:\Program Files\Nunit\bin

, , โ†’

-OR -

nant script, script :

set PATH="%PATH%;c:\Program Files\Nunit\bin"

powershell, :

$env:PATH += ';c:\program files\nunit\bin'

c:\Program Files ... Powershell , $env:ProgramFiles ${env:ProgramFiles(x86)}... , %PROGRAMFILES% , , . set, .

nunit , , , , script , nunit PATH.

+3

Source: https://habr.com/ru/post/1776941/


All Articles