我可以通过使用程序的 setup.exe 和 shimgen 来创建带有 Chocolatey 的静默安装程序吗?
Can I create a silent installer with Chocolatey by just using the setup.exe of a program and shimgen?
在尝试为某个程序创建静默安装程序时,我可以只使用工具文件夹中该程序的 setup.exe
并为其生成填充程序吗?如果是这样,那么它会安装到哪里?
例如,我删除了工具文件夹中的所有项目,并为 ARM RVDS 4.1
放入了 setup.exe
。当我这样做时 choco pack
它生成了一个垫片,但现在我不知道如何处理它,或者我是否做对了。
您不想为安装程序设置垫片 - 您想要从 chocolateyInstall.ps1
调用安装程序来安装程序。在 chocolateyInstall.ps1
中如何为安装程序 exe 执行此操作的示例是:
$packageInstallArgs = @{
PackageName = 'package-name'
FileType = 'exe'
SilentArgs = '/q /someOtherArguments' # This line is going to be installer specific, and is just a sample here
File = 'C:\Path\to\installer' # can be a relative path too
ValidExitCodes = 0, 1638 # array of acceptable return codes for the installer
}
Install-ChocolateyInstallPackage @packageInstallArgs
If your setup.exe
is embedded inside the package, you can reference the current package folder directory with the following environment variable: $env:chocolateyPackageFolder
. This variable only exists in the context of a Chocolatey package install. See here for more information on Chocolatey environment variables.
关于上面代码的一些细节:
- PackageName:这是包的名称 (id)
- 文件类型:这是 'exe' 还是 'msi'?
- SilentArgs:执行程序静默安装所需的任何参数
- 文件:安装程序文件的相对或绝对路径
- ValidExitCodes:应被视为成功安装的任何退出代码。我在示例中使用的那些意味着成功 (
0
) 并且需要重新启动 (1638
)。有关标准安装程序退出代码的更多信息,请参阅 this page。搜索以 ERROR_SUCCESS
开头的错误代码以获得您可能需要支持的成功代码。
为方便起见,您可以选择为未自动放置在 PATH 上的程序生成填充程序,以防填充程序未自动生成。
程序的安装位置取决于安装程序的默认位置,以及安装程序是否允许您覆盖它。
请注意,虽然自动生成的垫片会在卸载时自动删除,但使用 Install-BinFile
need to be manually removed on package uninstall using Uninstall-BinFile
从 chocolateyUninstall.ps1
创建的垫片。
这里有一些关于垫片的更多信息:
如果您将可执行文件放在 tools 文件夹中,那么 Chocolatey 会在安装包时为其创建一个 shim。 shim 允许可执行文件在路径上可用。
您想要做的是 运行 安装包时的安装程序,您可以使用 chocolateyInstall.ps1
文件来完成。如果您 运行 choco new <packagename>
您将获得一个示例 chocolateyInstall.ps1
文件,您可以将其用作模板。
在尝试为某个程序创建静默安装程序时,我可以只使用工具文件夹中该程序的 setup.exe
并为其生成填充程序吗?如果是这样,那么它会安装到哪里?
例如,我删除了工具文件夹中的所有项目,并为 ARM RVDS 4.1
放入了 setup.exe
。当我这样做时 choco pack
它生成了一个垫片,但现在我不知道如何处理它,或者我是否做对了。
您不想为安装程序设置垫片 - 您想要从 chocolateyInstall.ps1
调用安装程序来安装程序。在 chocolateyInstall.ps1
中如何为安装程序 exe 执行此操作的示例是:
$packageInstallArgs = @{
PackageName = 'package-name'
FileType = 'exe'
SilentArgs = '/q /someOtherArguments' # This line is going to be installer specific, and is just a sample here
File = 'C:\Path\to\installer' # can be a relative path too
ValidExitCodes = 0, 1638 # array of acceptable return codes for the installer
}
Install-ChocolateyInstallPackage @packageInstallArgs
If your
setup.exe
is embedded inside the package, you can reference the current package folder directory with the following environment variable:$env:chocolateyPackageFolder
. This variable only exists in the context of a Chocolatey package install. See here for more information on Chocolatey environment variables.
关于上面代码的一些细节:
- PackageName:这是包的名称 (id)
- 文件类型:这是 'exe' 还是 'msi'?
- SilentArgs:执行程序静默安装所需的任何参数
- 文件:安装程序文件的相对或绝对路径
- ValidExitCodes:应被视为成功安装的任何退出代码。我在示例中使用的那些意味着成功 (
0
) 并且需要重新启动 (1638
)。有关标准安装程序退出代码的更多信息,请参阅 this page。搜索以ERROR_SUCCESS
开头的错误代码以获得您可能需要支持的成功代码。
为方便起见,您可以选择为未自动放置在 PATH 上的程序生成填充程序,以防填充程序未自动生成。
程序的安装位置取决于安装程序的默认位置,以及安装程序是否允许您覆盖它。
请注意,虽然自动生成的垫片会在卸载时自动删除,但使用 Install-BinFile
need to be manually removed on package uninstall using Uninstall-BinFile
从 chocolateyUninstall.ps1
创建的垫片。
这里有一些关于垫片的更多信息:
如果您将可执行文件放在 tools 文件夹中,那么 Chocolatey 会在安装包时为其创建一个 shim。 shim 允许可执行文件在路径上可用。
您想要做的是 运行 安装包时的安装程序,您可以使用 chocolateyInstall.ps1
文件来完成。如果您 运行 choco new <packagename>
您将获得一个示例 chocolateyInstall.ps1
文件,您可以将其用作模板。