Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I include an MSI file inside a Chocolatey 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?

like image 824
San Zhang Avatar asked Aug 18 '15 20:08

San Zhang


Video Answer


1 Answers

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 image 188
Gary Ewan Park Avatar answered Sep 21 '22 20:09

Gary Ewan Park