ShaneKm
ShaneKm

Reputation: 21328

TFS check if file exists in build directory

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

Upvotes: 0

Views: 2027

Answers (3)

ShaneKm
ShaneKm

Reputation: 21328

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().

Upvotes: 0

jessehouwing
jessehouwing

Reputation: 114741

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

Upvotes: 0

Andy Li-MSFT
Andy Li-MSFT

Reputation: 30392

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

Upvotes: 0

Related Questions