Howto get the Checkout directory in MSTest Unittest with Teamcity Version 9.1.1
Hi,
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.
Question:
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)?
Please sign in to leave a comment.
Hi Beat,
Inside the MSBuild build script you can use teamcity.build.checkoutDir 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.
Hi
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
You can define environmental variable in your build configuration properties that will contain path to checkout directory:
with valueIn your tests you can access it by calling
Environment.GetEnvironmentVariable("CheckoutDir")This!
Thanks a lot