持续集成

我一直致力于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   我因为它不存在。   在C:\ Documents and Settings \ bdunbar \ My Documents \ Visual Studio 2008 \ Projects \ C.   gmFamilyComm \ scripts \ cms.ps1:4 char:27   + $ iirfpath =(resolve-path <!> lt; <!> lt; <!> lt; <!> lt; ../ iirf / cms / isapirewrite4.dll).path,

     

Resolve-Path:找不到路径'C:\ Documents and Settings \ bdunbar \ My Documents   \ Visual Studio 2008 \ Projects \ CgmFamilyComm \ FamilyComm \ familycomm'因为它确实如此   不存在。   在C:\ Documents and Settings \ bdunbar \ My Documents \ Visual Studio 2008 \ Projects \ C.   gmFamilyComm \ scripts \ cms.ps1:5 char:27   + $ vdirpath =(resolve-path <!> lt; <!> lt; <!> lt; <!> lt; ../ familycomm).path

有办法解决这个问题吗?在<=>

下运行<=>会出现问题吗?

[更新]

我已经能够改变一些事情以解决正在发生的错误,但我仍然收到来自powershell命令提示符的完全正常的错误。我无法弄清楚区别是什么。

有帮助吗?

解决方案

我过去曾做过这项工作(请参阅 http:// sharepointpdficon.codeplex.com/SourceControl/changeset/view/13092#300544 如有兴趣):

  

C:\ WINDOWS \ system32 \ windowspowershell \ v1.0 \ powershell.exe -NoLogo   -NonInteractive -Command。'$(ProjectDir)Deployment \ PostBuildScript.ps1'   -ProjectDir:'$(ProjectDir)' - ConfigurationName:'$(ConfigurationName)' - TargerDir:'$(TargetDir)' - TargetFileName:'$(TargetFileName)' - TargetName:'$(TargetName)

然后将这些参数放在构建后脚本的第一行(如果您认为可以使用它们):

param($ProjectDir, $ConfigurationName, $TargetDir, $TargetFileName)

我也应该指出,我目前没有使用它。我确实喜欢将它用作快速暂存器来重新加载测试数据以进行集成测试。

其他提示

看起来您的问题是如何解析相对路径。相对路径基于当前位置(存储在$pwd中)而不是基于脚本的位置来解析。因此,如果您从C:\启动脚本,那肯定是行不通的。

我建议您根据参数计算路径(如Peter Seale所示),或者从以下位置获取脚本的实际位置:

$MyInvocation.MyCommand.Path
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top