Can I include an MSI file inside a Chocolatey package?
Asked Answered
T

2

9

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?

Taken answered 18/8, 2015 at 20:12 Comment(1)
Actually it might just be as simple as putting the msi under tools(or anywhere under the package directory), and just replace the "url" argument of "Install-ChocolateyInstallPackage" with the path to the msi to use it. Going to try if that works.Taken
N
10

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.

Nagy answered 19/8, 2015 at 6:40 Comment(1)
Thank you Gary. I actually got it working that day. I went through the same link about mounting the iso, too. The thorough information you provide can definitely be helpful to others who have similar problems.Taken
T
2

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.

Thundershower answered 19/8, 2015 at 13:20 Comment(3)
It's not that it's not a good idea because of slow feedback, but usually it's an issue with distribution rights (the legal stuff). And sometimes it is the sheer size of the installer file. Somewhere around 20-25MB is probably the max that you'd want a choco file. Plus no feedback on downloading the package (at least not yet).Pulsifer
Yes, the distribution rights is another very important point. Of course, we don't have the context to "answer" Yu Gu definitively.Thundershower
Thanks for the heads up guys. The reason I want to put the msi inside the package instead of using extra URL is simply because that I am afraid the link will become invalid in the future.Taken

© 2022 - 2024 — McMap. All rights reserved.