我有一个非常基本的ChocolateyInstall.ps1
脚本,应该在父文件夹中调用另一个Powershell脚本。这是我的项目结构:
project/
service-install.ps1
tools/
chocolatey/
ChocolateyInstall.ps1
这是我的ChocolateyInstall.ps1
:
# Install the windows service
Start-ChocolateyProcessAsAdmin -ExeToRun "powershell" -Statements "./service-install.ps1" -WorkingDirectory "..\..\"
在安装构建软件包时,ChocolateyInstall.ps1
失败,并显示以下错误:
<S S="Error">./service-install.ps1 : The term './service-install.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again._x000D__x000A_</S>
<S S="Error">At line:7 char:9_x000D__x000A_</S>
<S S="Error">+ ./service-install.ps1_x000D__x000A_</S>
<S S="Error">+ ~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S>
<S S="Error"> + CategoryInfo : ObjectNotFound: (./service-install.ps1:String) [], ParentContainsErrorRecordException_x000D__x000A_</S>
<S S="Error"> + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S>
<S S="Error"> _x000D__x000A_</S>
我需要使用project/
目录作为工作目录来运行脚本。
为什么未正确执行/发现服务安装脚本?我已经尝试过command的示例,但仍然无法使其正常工作。
答案 0 :(得分:0)
在大多数Chocolatey包装中,您将看到类似以下内容的行:
$ScriptRoot = Split-Path $MyInvocation.MyCommand.Definition
这将为您提供当前正在执行的脚本的位置,即ChocolateyInstall.ps1文件。从那里,您应该能够“找到”要执行的脚本。