TFS check if file exists in build directory

1.8k views Asked by At

Is there a way to check if a specific .xml file exists in build directory when TFS build runs?

I'm trying to get a Boolean result true/false based on the result found/not found

I tried creating a variable that would store this result (I'm guessing that is the way to do it). However I get an error when trying to use it. enter image description here

3

There are 3 answers

0
ShaneKm On BEST ANSWER

Found the solution. I added a new variable "dcMatchedFile" - which is a IEnumerable type. Use this dcMatchedFile as "Result" option for FindMatchingFiles" item (see images below)

enter image description here

enter image description here

Then you can simply use "If" statement to check Any().

0
jessehouwing On

The expression editor uses standard VB.NET, so you can call into System.IO.File.Exists(path) to detect whether a file already exists.

0
Andy Li-MSFT On

You can try writing a script to check if the specific file exist, then check in the script and run as Pre-build script in your build process:

e.g.:

$Source = $Env:TF_BUILD_BUILDDIRECTORY
$filename = "*.xml"

if (!(Test-Path "$Source\$filename"))
{
  Write-Warning "$filename absent from build directory"
  # Write-Error "$filename absent from build directory"
  #exit 1
}

Reference Using Environment Variables in Visual Studio 2013 and TFS 2013