我很难找到一种方法来让 git 和 poshgit 在使用巧克力通过脚本安装它而不关闭 powershell 控制台后工作。
这是我的脚本目前的样子。
Function InstallChocolatey {
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
refreshenv #needed to make poshgit install succesfully without restarting Powershell
Write-Output "Chocolatey installed and configured."
}
Function InstallSoftware {
choco install git --params='/NoShellIntegration' -y
choco install poshgit -y
. $profile #reload profile
Write-Output "Software installed and profile reloaded"
}
InstallChocolatey
InstallSoftware
当我关闭 Powershell 并重新启动它时,一切都按预期工作。但是由于我的脚本以后应该继续执行 git 的东西,我真的很想找到一个解决方案,让它在不关闭控制台的情况下工作。
根据我在 Stackoverflow 和其他网站上使用的发现
. $profile
应该重新加载配置文件。但不幸的是,我的情况似乎没有任何效果。我尝试再次使用 refreshenv。
我的个人资料文件目前只包含一行
Import-Module 'C:\tools\poshgit\dahlbyk-posh-git-a4faccd\src\posh-git.psd1'
我还尝试在行尾添加 -force 但没有任何改变。
我对 Powershell 很陌生,所以请多多包涵…… :)