Howto get the Checkout directory in MSTest Unittest with Teamcity Version 9.1.1


In my unittest code, i need to access some files which are part of my checkout directory.

I've done this till version 9 of teamcity with the following code:

new DirectoryInfo(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath))

This woul've returned the Out directory of the MSBuild, and this Out directory was located within the Checkout directory.
In version 9.1.1, it seems this has changed, and will return a path below the teamcity build temp directory.

As workaround, i use currently the following code:

new System.Diagnostics.StackFrame(true).GetFileName()

This will return the sourcefile path which currently is executed. Based on this path, i then can navigate to my files.

Is this change of msbuild temp directory known?

Is there an official/better way of getting the checkout directory when using mstest(Using some teamcity variables in the MSBuild c# code)?

Comment actions Permalink

Hi Beat,

Inside the MSBuild build script you can use parameter. For MSBuild use $(<property name>). Note that MSBuild does not support names with dots ("."), so you need to replace "." with "_" when using the property inside the build script. Please read more about it here.

Comment actions Permalink


I don't need the path in MSBuild, but in MSTest unit tests.
I need to get the path from c# code in a unit test

Comment actions Permalink

You can define environmental variable in your build configuration properties that will contain path to checkout directory:

with value

In your tests you can access it by calling

Comment actions Permalink

Thanks a lot


Please sign in to leave a comment.