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
Set-AzureDeployment 不是在当前目录中查找 ServiceConfigiration.Test.cscfg
文件,而是希望在当前用户的主目录中找到此文件,该文件坦率地说,非常令人讨厌。
是否有一些常见的 Powershell 模式可以从主目录开始运行所有 cmdlet 函数?为什么?
最佳答案
您可以显式传递完整路径:
Set-AzureDeployment -Config -ServiceName pms-dimon -Slot "Production" `
-Configuration $(rvpa .\ServiceConfiguration.Test.cscfg) -Verbose
回答你的问题:不,PowerShell 对主目录没有做任何特殊的事情。但是,如果您执行 cd
,则暴露给非 PowerShell 命令的当前目录的值 ([Environment]::CurrentDirectory
) 不会更改,这通常是源的惊喜。如果 Set-AzureDeployment
将其参数传递给非 PowerShell 命令,则可以解释该行为。
要以一般方式解决此问题,您只需在发出进一步命令之前将当前目录更改为 PowerShell 的位置即可:
[Environment]::CurrentDirectory = $(pwd)
显然,这只适用于当前位置位于文件系统中的情况,而不适用于 PowerShell 支持的任何其他特殊位置。
关于powershell - Set-AzureDeployment 忽略相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28565764/