【问题标题】:Run command on local build, but not TFS build在本地构建上运行命令,但不是 TFS 构建
【发布时间】:2014-10-22 12:53:55
【问题描述】:

我的构建后事件是:

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

这将检查目标构建程序集文件。这就是我想要的,而且在 VS 中效果很好。

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

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

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

'"*Undefined*TF.exe"' 不是内部或外部命令、可运行程序或批处理文件。

如何在不评估可执行文件是否首先存在的情况下有条件地执行此语句?

【问题讨论】:

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


    【解决方案1】:

    要像这样有条件地运行命令,请使用 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)"') }
    

    【讨论】:

      猜你喜欢
      • 2020-12-28
      • 2013-09-28
      • 1970-01-01
      • 2017-06-26
      • 2019-09-26
      • 2014-03-18
      • 1970-01-01
      • 2012-05-06
      • 2018-02-23
      相关资源
      最近更新 更多