Running MsTest.exe from Batch script
<p>I am trying to automate running a C# solution's unit tests from a batch script.</p>

<p>My script is working fine, until it comes to actually calling MsTest.exe with the /testcontainer and /test flags in the MsTest call.</p>

<p>Batch script below:</p>

<pre><code>@echo OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

echo Detecting System specification...
echo.

reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" &gt; NUL &amp;&amp; set OS=32BIT || set OS=64BIT

set programFilesPath=xyz

if %OS%==32BIT (
    echo 32bit operating system detected.
    echo.
    set programFilesPath=%ProgramFiles%\Microsoft Visual Studio
) ELSE (
    echo 64bit operating system detected.
    echo.
    set programFilesPath=%ProgramFiles(x86)%\Microsoft Visual Studio
)

echo Checking for Visual Studio installations...
echo.

set /a highestVSVersion=54
set /a installationPath=xyz
set /a vsCount=0

for /d %%a in ("%programFilesPath%"*) do (

    rem echo "%%a"
    rem set installationPath=%%a
    rem echo !installationPath!
    rem echo !vsCount!

    for /f "tokens=5" %%g in ("%%a") do (
        set tempStr=%%g
        set tempStr=!tempStr:~0,2!

        if not "!tempStr!"=="!tempStr:.=!" (
            set tempStr=!tempStr:.=!
        )

        set tempTwo=0
        set tempTwo=!tempStr!

        if !vsCount! EQU 0 (
            set highestVSVersion=!tempTwo!
        ) else (
            if !tempTwo! GTR !highestVSVersion! (
                set highestVSVersion=!tempTwo!
            )
        )
    )

    set /a vsCount=!vsCount!+1
)

if !vsCount! EQU 0 (
    echo No Visual Studio installation found. Please install visual studio to run unit tests.   
    echo.
) else (

    if !highestVSVersion! GTR 9 (
        set highestVSVersion=!highestVSVersion!.0
    )

    echo Visual Studio !highestVSVersion! found.
    echo.
    echo Verifiying MsTest.exe location for Visual Studio !highestVSVersion!...
    echo.
    set fullPath=!programFilesPath! !highestVSVersion!\Common7\IDE\MsTest.exe

    if exist !fullPath! (
        echo MsTest.exe found at: !fullPath!
        echo.
        echo Running all tests in src\DictionaryDash.Testing
        set testContainerArg=src\DictionaryDash.Testing\bin\Release\DictionaryDash.Testing.dll

        call "!fullPath!" /testcontainer: !testContainerArg!
    )
)

pause
</code></pre>

<p>Where I am having trouble is the last call line. I get the following output in the command window:</p>

<pre><code>Detecting System specification...

32bit operating system detected.

Checking for Visual Studio installations...

Visual Studio 12.0 found.

Verifiying MsTest.exe location for Visual Studio 12.0...

MsTest.exe found at: C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\M
sTest.exe

Running all tests in src\DictionaryDash.Testing

Microsoft (R) Test Execution Command Line Tool Version 12.0.21005.1

Copyright (c) Microsoft Corporation. All rights reserved.

Invalid switch "src\dictionarydash.testing\bin\release\dictionarydash.testing.dl
l".

Please specify a parameter for the /testcontainer switch.

For switch syntax, type "MSTest /help"

Press any key to continue . . .
</code></pre>

<p>It is successfully finding MsTest.exe but when it comes to passing an argument to the /testcontainer switch that it fails. The script file is located in the root of the project directory at the same level as the "src" directory.</p>

<p>Thanks!</p>