Set-AzureDeployment忽略相对路径

3
PS C:\Users\dimon\src\panama\Panama> Set-AzureDeployment -Config -ServiceName pms-dimon -Slot "Production" -Configuration .\ServiceConfiguration.Test.cscfg -Verbose
Set-AzureDeployment : Could not find a part of the path 'C:\Users\dimon\ServiceConfiguration.Test.cscfg'.
At line:1 char:1
+ Set-AzureDeployment -Config -ServiceName pms-dimon -Slot "Production" -Configur ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-AzureDeployment], DirectoryNotFoundException
    + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.WindowsAzure.Commands.ServiceManagement.HostedServices.SetAzureDeploymentCommand

与其在当前目录中查找ServiceConfigiration.Test.cscfg文件,Set-AzureDeployment期望在当前用户的主目录中找到该文件,这实际上相当麻烦。

是否有一些常见的PowerShell模式可以从主目录运行所有的cmdlet函数?为什么?


相对路径是否被视为管道值?如果是这样,根据MSDN,"-Configuration"开关不接受管道值。 - Trey Nuckolls
我很好奇-Configuration如何处理那个字符串数据。它接受一个字符串,但是它正在尝试进行某种翻译。Resolve-Path可能是一个解决方法,但我对-Configuration参数的定义及其数据验证很感兴趣。 - Matt
1个回答

1
您可以明确地传递完整路径:
Set-AzureDeployment -Config -ServiceName pms-dimon -Slot "Production" `
  -Configuration $(rvpa .\ServiceConfiguration.Test.cscfg) -Verbose

回答您的问题:不,PowerShell对主目录没有特殊处理。但是,暴露给非PowerShell命令的当前目录值([Environment]::CurrentDirectory)如果执行 cd 命令,将不会改变,这经常会导致一些意外情况。如果 Set-AzureDeployment 将其参数传递给非PowerShell命令,那么这就解释了这种行为。

为了以一般方式解决这个问题,在进一步发出命令之前,可以简单地将当前目录更改为 PowerShell 的位置:

[Environment]::CurrentDirectory = $(pwd)

显然,这仅适用于当前位置在文件系统中的情况,而不是 PowerShell 支持的任何其他奇特位置。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接