Can I put an MSI file or ISO image into a Chocolatey package?
So when I choco install foo
, it won't download the MSI from another URL, but take the file from inside the package?
Can I put an MSI file or ISO image into a Chocolatey package?
So when I choco install foo
, it won't download the MSI from another URL, but take the file from inside the package?
Yes, this is definitely possible. This is actually exactly what the ChocolateyGUI package does. You can see its .nuspec file here:
https://github.com/chocolatey/ChocolateyGUI/blob/develop/nuspec/chocolatey/ChocolateyGUI.nuspec
<?xml version="1.0"?>
<package>
<metadata>
<id>chocolateygui</id>
<version>$version$</version>
<title>Chocolatey GUI</title>
<authors>Chocolatey</authors>
<owners>Chocolatey</owners>
<projectUrl>https://github.com/chocolatey/ChocolateyGUI</projectUrl>
<projectSourceUrl>https://github.com/chocolatey/ChocolateyGUI</projectSourceUrl>
<packageSourceUrl>https://github.com/chocolatey/ChocolateyGUI/tree/develop/nuspec/chocolatey</packageSourceUrl>
<iconUrl>https://raw.githubusercontent.com/chocolatey/choco/master/docs/logo/chocolateyicon.gif</iconUrl>
<licenseUrl>https://raw.githubusercontent.com/chocolatey/ChocolateyGUI/develop/LICENSE</licenseUrl>
<bugTrackerUrl>https://github.com/chocolatey/ChocolateyGUI/issues</bugTrackerUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
Chocolatey GUI is a nice GUI on top of the Chocolatey command line tool.
## Features
* View all **installed** and **available** packages
* **Update** installed but outdated packages
* **Install** and **uninstall** packages
* See detailed **package information**
## Notes
This package will only work correctly on Windows 7 SP1 through Windows 10 (1708) or Windows Server 2008 R2 SP1 through Windows Server 2016, and requires .NET Framework 4.5.2 at minimum.
</description>
<summary>A GUI for Chocolatey</summary>
<releaseNotes>
All release notes for Chocolatey GUI can be found on the GitHub site - https://github.com/chocolatey/ChocolateyGUI/releases
</releaseNotes>
<tags>chocolateygui chocolatey admin foss</tags>
<dependencies>
<dependency id="Chocolatey" version="[0.10.3, 0.11)" />
</dependencies>
</metadata>
<files>
<file src="chocolateyInstall.ps1" target="tools"/>
<file src="chocolateyUninstall.ps1" target="tools"/>
<file src="..\..\BuildArtifacts\ChocolateyGUI.msi" target="tools"/>
<file src="..\..\LICENSE" target="tools\LICENSE"/>
<file src="VERIFICATION.txt" target="tools"/>
</files>
</package>
Then, as you pointed out, you would then use Install-ChocolateyInstallPackage to perform the installation, which would then use the local MSI within the package, rather than first downloading it. You can see the installation script for ChocolateyGUI here:
https://github.com/chocolatey/ChocolateyGUI/blob/develop/nuspec/chocolatey/chocolateyInstall.ps1
$ErrorActionPreference = 'Stop';
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$fileLocation = Join-Path $toolsDir 'ChocolateyGUI.msi'
$packageArgs = @{
packageName = $env:ChocolateyPackageName
softwareName = 'Chocolatey GUI'
file = $fileLocation
fileType = 'msi'
silentArgs = "/qn /norestart /l*v `"$env:TEMP\$env:ChocolateyPackageName.$env:ChocolateyPackageVersion.log`""
validExitCodes= @(0,1641,3010)
}
Install-ChocolateyInstallPackage @packageArgs
Remove-Item -Force $packageArgs.file
You can do the exact same thing with an ISO image file, and there is a walkthrough on the established best practice for using that ISO file here:
How To Mount An Iso In Chocolatey Package
NOTE: If you are planning on pushing the package to Chocolatey.org, please bear in mind the size of the MSI/ISO file. If this is especially large, it is probably best not to include it within the nupkg, but rather use a download link.
Like Gary said, you can include arbitrary files in the package.
I'd emphasize that it's not a great idea. You have to download the package file itself (that's what happens when you choco install foo
). Moving the MSI/ISO inside the package means you'll be downloading it with the package file and, depending on the size, slowing down feedback at the console.
Using the proper helpers and external URLs gives you a lot of great behaviors, least of which, is the download progress bar!
If file storage is a problem, there are many free options including: GitHub, Google Drive, DropBox, etc. If you're creating "internal" packages for your company, a network share can work with file://
URLs.
© 2022 - 2024 — McMap. All rights reserved.