4

I have an MSTest build step in my TeamCity build. Some of the tests are looking for a file in a relative path which they cannot find and the tests are throwing the error...

Cannot find path...

'C:\BuildAgent\temp\buildTmp\SYSTEM_[AGENT NAME] 2013-02-06 16_25_11\Documents\json.value.list.txt'

I have a PowerShell script that I want to use to create and copy the file out to the above path. However, I cant seem to figure out the appropriate TeamCity parameters to use to construct the path...

I have...

%system.teamcity.build.tempDir%\%teamcity.agent.name%\documents

However, that gives me...

'C:\BuildAgent\temp\buildTmp[AGENT NAME]\Documents\'

What can parameters or TeamCity variables can I use to construct...

C:\BuildAgent\temp\buildTmp\SYSTEM_[AGENT NAME] 2013-02-06 16_25_11\Documents

Thanks!

xspydr
  • 3,030
  • 3
  • 31
  • 49
  • I'm having the same issue. Did you solve it, please? – alansiqueira27 Dec 04 '15 at 17:42
  • Check this question/answer out https://stackoverflow.com/questions/31183858/copying-to-teamcitys-out-directory-before-running-unit-tests it might help, as it did for me. – r0bb077 Mar 26 '18 at 23:47

1 Answers1

1

If your test is reading the contents of a file, this will ensure that relative paths are resolved correctly so tests can be run on TeamCity as well as locally:

string currentDir = new System.Diagnostics.StackFrame(true).GetFileName();
var workingFile = new FileInfo(currentDir);
string fileContents = File.ReadAllText(workingFile.Directory + relativeFilePath);

relativeFilePath is the variable containing the file. fileContents will contain the contents of this file when run from TeamCity or locally.

infojolt
  • 5,244
  • 3
  • 40
  • 82
  • I don't want to change the way the tests read the files. I simply want to construct the same path the tests are looking for on the TeamCity server... – xspydr Feb 13 '13 at 16:00