在本地构建上运行命令,但不在TFS构建上运行

时间:2014-10-22 12:53:56

标签: batch-file tfsbuild post-build-event

我的构建后活动是:

"$(DevEnvDir)TF.exe" checkout "$(TargetPath)"

这将检出目标构建程序集文件。这就是我想要的,它在VS中很有用。

在构建服务器上,$(DevEnvDir)等于*Undefined*。所以,我将后期构建事件修改为以下内容:

IF NOT "$(DevEnvDir)" == '*Undefined*' "$(DevEnvDir)TF.exe" checkout "$(TargetPath)"

问题是,它仍在评估$(DevEnvDir)TF.exe是否是可执行文件,并且在构建服务器上它评估为*Undefined*TF.exe,这会引发此错误:

  

'" *未定义* TF.exe"'不被识别为内部或外部命令,可操作程序或批处理文件。

如果没有评估可执行文件是否首先存在,我怎么能有条件地执行这个语句?

1 个答案:

答案 0 :(得分:0)

要像这样有条件地运行命令,请使用PowerShell:

if ('$(DevEnvDir)' -ne '*Undefined*') { [System.Diagnostics.Process]::Start('$(DevEnvDir)TF.exe', 'checkout "$(TargetPath)"') }

将其包装在干净的PS环境中:

powershell -windowstyle hidden -nologo -noprofile if ('$(DevEnvDir)' -ne '*Undefined*') { [System.Diagnostics.Process]::Start('$(DevEnvDir)TF.exe', 'checkout "$(TargetPath)"') }