Reputation: 649
I have this very basic ChocolateyInstall.ps1
script that should call another Powershell script in a parent folder. This is my project structure:
project/
service-install.ps1
tools/
chocolatey/
ChocolateyInstall.ps1
And this is my ChocolateyInstall.ps1
:
# Install the windows service
Start-ChocolateyProcessAsAdmin -ExeToRun "powershell" -Statements "./service-install.ps1" -WorkingDirectory "..\..\"
When installing the build package, the ChocolateyInstall.ps1
fails with this error:
<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>
I need to run the script with the project/
directory as workdir.
Why isn't the service install script properly executed / found? I already tried the examples of the command but still can't get it to work.
Upvotes: 1
Views: 286
Reputation: 18991
In most Chocolatey packages, you will see a line similar to this:
$ScriptRoot = Split-Path $MyInvocation.MyCommand.Definition
This will give you the location of the currently executing script, i.e. the chocolateyInstall.ps1 file. From there, you should be able to "find" the script that you want to execute.
Upvotes: 1