Reputation: 41718
How do I programmatically determine the path of my source code when running unit tests in Visual Studio Online's hosted build infrastructure.
Why do I want to know this? I want an integration test to run redis-server.exe
from the Redis-64
NuGet package so that it can run tests that use Redis.
FWIW, here are the environment variables from the Visual Studio Online build server:
PROCESSOR_ARCHITEW6432=AMD64
COMPUTERNAME=BUILD-0012
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
GTK_BASEPATH=C:\Program Files (x86)\GtkSharp\2.12\
VSSDK140Install=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\
VSSDK120Install=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\
PROCESSOR_REVISION=2d07
VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
TMP=C:\Users\BUILDG~1\AppData\Local\Temp
TEMP=C:\Users\BUILDG~1\AppData\Local\Temp
LOCALAPPDATA=C:\Users\buildguest\AppData\Local
PUBLIC=C:\Users\Public
ANDROID_HOME=C:\java\androidsdk\android-sdk
M2_HOME=C:\java\maven\apache-maven-3.2.2
JAVA_HOME=C:\java\jdk\jdk1.8.0_25
USERDOMAIN=BUILD-0012
ProgramFiles(x86)=C:\Program Files (x86)
Path=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Users\VssAdministrator\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\
PROCESSOR_LEVEL=6
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 45 Stepping 7, GenuineIntel
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\SharePoint Online Management Shell\;C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\
NUMBER_OF_PROCESSORS=2
CommonProgramFiles=C:\Program Files (x86)\Common Files
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
ProgramW6432=C:\Program Files
ProgramFiles=C:\Program Files (x86)
FP_NO_HOST_CHECK=NO
EnableNuGetPackageRestore=True
SystemRoot=C:\Windows
VSSDK110Install=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VSSDK\
CommonProgramW6432=C:\Program Files\Common Files
USERPROFILE=C:\Users\buildguest
VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
APPDATA=C:\Users\buildguest\AppData\Roaming
ProgramData=C:\ProgramData
ANT_HOME=C:\java\ant\apache-ant-1.9.4
WIX=C:\Program Files (x86)\WiX Toolset v3.7\
XNAGSShared=C:\Program Files (x86)\Common Files\Microsoft Shared\XNA\
VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
USERNAME=buildguest
PROCESSOR_ARCHITECTURE=x86
OS=Windows_NT
ComSpec=C:\Windows\system32\cmd.exe
ANDROID_NDK_HOME=C:\java\androidsdk\android-ndk-r10d
SystemDrive=C:
windir=C:\Windows
ALLUSERSPROFILE=C:\ProgramData
Upvotes: 0
Views: 674
Reputation: 8353
TF_BUILD_SOURCESDIRECTORY
works as documented here in pre-post test scripts.
They are not available in the VSTestRunner activity.
So you should prepare your application using a pre-test script, where you can grab stuff from known build places.
NOTE The environment variables are available only with later build templates, like TfvcTemplate.12.xaml and GitTemplate.12.xaml. The DefaultTemplate.11.xaml shows only TF_BUILD.
Upvotes: 1
Reputation: 41718
Type C:\a\src
into your source code. At least the path is always the same, but I hope there's a better answer.
Upvotes: 0