如何在psake脚本中调试/诊断Powershell Copy-Item命令失败的原因?

时间:2011-07-18 07:51:14

标签: powershell psake

我有一个非常简单的脚本,它在 psake 约定(和示例)之后的任务构建部分中使用了Copy-Item。现在,这只是为了简化脚本以调试此问题。

错误:

  

18/07/2011 5:40:57 PM:发生错误:

     

Exec:执行命令时出错:Copy-Item“$ src_dir .. \ somefolder * .dll”$ bin_dir

我试过通过Write-Host输出文件路径,看起来很好。

我需要一些帮助,请调试一下,让脚本代码(Copy-Item)独立工作 psake 不是一个目标。

剧本:

Properties {
    $src_dir = Split-Path $psake.build_script_file
    $bin_dir= "$build_dir\..\Binaries\"
}

include .\psake_ext.ps1

Task Build -Depends Clean, Init {
    Write-Host "about to error here:"

    Exec { Copy-Item "$src_dir\..\somefolder\*.dll" $bin_dir }

    Write-Host "do NOT get this far"
    #more similar Exec copy commands, that don't execute
}

Task Clean {    

}

另请注意:

  

这个脚本正在运行,但最近才断断续续地失败,   但现在看来似乎更失败了。

执行:

.\psake.ps1 "failing-copy-script.ps1" Build

1 个答案:

答案 0 :(得分:1)

所以这个问题有一个答案,总结了问题的评论和其他信息:

如果您遇到此问题,请执行以下诊断步骤:

  1. “你试过把它关掉再打开吗?” - 关闭可能与脚本有关的任何内容,包括IDE,甚至重新启动计算机。
  2. 尝试使用lockhunter
  3. 等工具
  4. 如果不需要,请避免使用'Exec {bla}'命令。
  5. 使用Process Explorer
  6. 搜索挂钩
相关问题