持续集成
我一直在开发一个PowerShell脚本,以使我们的开发过程保持流线型。我计划将它作为后期构建活动来运行,但我遇到了一些麻烦。
在PowerShell提示符下,以下命令运行得非常好:
PS C:\> ./example.ps1
但是,当尝试从cmd.exe
运行此命令时,请执行以下操作:
C:\> powershell -command "&\"C:\path to script\example.ps1\""
脚本执行了,但我从PowerShell返回了一轮错误,主要是来自resolve-path
函数的路径解析错误:
Resolve-Path :找不到路径“”C:\ Documents and Settings\bdunbar\My Documents \Visual Studio 2008\Projects\CgmFamilyComm\FamilyComm\iirf\cms\isapirewrite4.dl l“”,因为它不存在。“在C:\Documents and Settings\bdunbar\My Documents\Visual Studio2008\Projects\C gmFamilyComm\scripts\cms.ps1:4 char:27 + $iirfpath = (resolve-path <<<< ../iirf/cms/isapirewrite4.dll).path,
解决路径:找不到路径'C:\Documents and Settings\bdunbar\My Documents \Visual Studio 2008\Projects\CgmFamilyComm\FamilyComm\familycomm‘’,因为它不存在。位于C:\Documents and Settings\bdunbar\My Documents\Visual Studio2008\Projects\C gmFamilyComm\scripts\cms.ps1:5 char:27 + $vdirpath = (resolve-path <<<< ../gmFamilyComm\scripts\cms.ps1:5).path
有没有办法解决这个问题?在cmd.exe
下运行resolve-path
会有问题吗
更新
我已经能够通过更改来避免正在发生的错误,但是我仍然可以从powershell命令提示符收到运行良好的错误。我想不出有什么不同。
发布于 2009-05-01 22:50:15
我以前做过这样的工作(如果感兴趣,请参阅http://sharepointpdficon.codeplex.com/SourceControl/changeset/view/13092#300544 ):
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe .'$(ProjectDir)Deployment\PostBuildScript.ps1‘- -Command项目目录:’$(ProjectDir)‘-配置名称:’$(ConfigurationName)‘-目标目录:’$(TargetDir)‘-目标文件名:’$(TargetFileName)‘-目标名称:’$(TargetName)‘
然后在构建后脚本的第一行中抛出这些参数(如果您认为您可以使用它们):
param($ProjectDir, $ConfigurationName, $TargetDir, $TargetFileName)
另外,我应该指出的是,我目前没有使用这个。我确实喜欢将其用作快速便签簿,以便重新加载测试数据以运行集成测试。
发布于 2009-05-02 23:44:15
看起来您的问题是如何解析相对路径。基于当前位置(存储在$pwd
中)解析相对路径,而不是基于脚本的位置。因此,如果您从C:\
启动该脚本,它肯定不会工作。
我建议您根据参数计算路径(就像Peter Seale展示的那样),或者从以下位置获取脚本的实际位置:
$MyInvocation.MyCommand.Path
https://stackoverflow.com/questions/813003
复制相似问题