【问题标题】:Psake Include method not workingPsake Include 方法不起作用
【发布时间】:2013-09-04 14:58:47
【问题描述】:

我正在使用 Psake 编写一个简单的 PS 脚本,但当我尝试包含另一个 ps1 文件时遇到问题。

    PS C:\CI> Include .\EnvSettings.ps1

我有这个例外

Exception calling "Peek" with "0" argument(s): "Stack empty."
At C:\Users\Julien\Documents\WindowsPowerShell\Modules\psake\psake.psm1:227 char:2
+     $psake.context.Peek().includes.Enqueue(($pa));
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidOperationException

我查看了 psake.psm1 第 227 行,看看发生了什么

# .ExternalHelp  psake.psm1-help.xml
function Include {
    [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=1)][string]$fileNamePathToInclude
    )
    Assert (test-path $fileNamePathToInclude -pathType Leaf) ($msgs.error_invalid_include_path -f $fileNamePathToInclude)
    $psake.context.Peek().includes.Enqueue((Resolve-Path $fileNamePathToInclude));
}

代码成功通过了 Assert 行。

问题来自 Resolve-Path $fileNamePathToInclude,它什么也没返回... 如果我从命令行尝试它,它工作正常。

以前有人遇到过这个问题吗?

【问题讨论】:

    标签: powershell psake


    【解决方案1】:

    包含文件的方式不是Include .\EnvSettings.ps1,而是"dot source"文件:

    . .\EnvSettings.ps1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-06
      • 2013-02-15
      • 1970-01-01
      • 2023-04-06
      • 2015-02-20
      • 2016-02-24
      • 1970-01-01
      相关资源
      最近更新 更多