As part of my answer here I had the same issue when trying to run my tests through TFS/Powershell. To fix it, I took @allen's advise to call the "Developer Command Prompt" before running the tests and implemented a solution in a Powershell script, seems to work for the two servers I've tested it on, I've adapted it to be BAT compatible:
**Note: This is for VS 2017, I believe you simply change the year in the path to invoke a previous version*
(For @user6329531, BAT version of the fix, call this before you execute the tests)
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
(My full Powershell script for running Microsoft "LoadTests")
param (
[string]$path = ""
)
#For this to work correctly you need to make sure the following things are done:
#https://stackoverflow.com/a/53211350/2912011
Write-Output $path
#Start deveng, for some reason it likes to complain if it's not runnning
#https://social.msdn.microsoft.com/Forums/vstudio/en-US/1d5574c0-4a56-4dd1-b390-3a3683278d16/loadtest-require-visual-studio-enterprise?forum=vstest
Start-Process "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe"
#Run the "Developer Command Prompt"
cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\"
./VsDevCmd.bat
#Navigate to the MSTest directory
cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\"
#Iterate through the entire directory, run each loadtest one at a time
$fullPath = $path
Get-ChildItem $fullPath -Filter *.loadtest |
Foreach-Object {
$content = $_.FullName
Write-Output $content
./mstest.exe /testcontainer:"$content" /detail:testtype
}
try {
Get-Process devenv -IncludeUserName | Where UserName -match EBMTFSServiceAccount| Stop-Process
}
catch {
#This may fail, if so it probably is not an issue, but we need to double check...
Write-Output $_.Exception.Message
}