TFS检查构建目录中是否存在文件

问题描述 投票:0回答:3

有没有办法在TFS构建运行时检查构建目录中是否存在特定的.xml文件?

我试图根据找到/未找到的结果得到布尔结果true / false

我尝试创建一个存储此结果的变量(我猜这是做的方法)。但是在尝试使用它时出现错误。 enter image description here

tfs tfsbuild xamlbuild
3个回答
0
投票

您可以尝试编写脚本来检查特定文件是否存在,然后检查脚本并在构建过程中以Pre-build script身份运行:

e.f.:

$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
}

参考Using Environment Variables in Visual Studio 2013 and TFS 2013


0
投票

表达式编辑器使用标准VB.NET,因此您可以调用System.IO.File.Exists(path)来检测文件是否已存在。


0
投票

找到了解决方案。我添加了一个新变量“dcMatchedFile” - 这是一个IEnumerable类型。使用此dcMatchedFile作为“FindMatchingFiles”项目的“结果”选项(参见下图)

enter image description here

enter image description here

然后你可以简单地使用“If”语句来检查Any()。

© www.soinside.com 2019 - 2024. All rights reserved.