Zero Install Bootstrapper – Part 1

The core feature of Zero Install is that you can use applications without having to install them first. This is accomplished by downloading and caching applications on first use, with dependency injection and secure hashing thrown into the mix. But how do you get Zero Install itself on your system? Do you install it using a Setup EXE, breaking the “no more installing” premise right from the start? We can do better than that!

When you download you get the Zero Install Bootstrapper. When launched, this EXE uses a copy of the Zero Install Backend libraries (bundled using ILRepack) to fetch and parse This feed tells the Bootstrapper which versions of Zero Install are currently available and how to download them. Next, the most recent stable release is downloaded, extracted to the regular Zero Install cache directory and executed from there.

What just happened here? We used a subset of Zero Install to download and run Zero Install itself. Pretty meta! When you run the Bootstrapper again it will launch straight into the cached copy of Zero Install without having to download it again.

But something is missing. This cached copy of Zero Install is not integrated into the system. There are no start menu entries, the command-line tools are not in the PATH, etc. This is by design; after all you may only need Zero Install once on that particular machine or may decide you don’t like it. In that case you can simply delete the Bootstrapper EXE and don’t have to clean anything up, much like a portable application.

But what if you do want proper system integration? You can choose to “deploy” a specific version of Zero Install to your system: First, the instance running from the cache directory copies itself to %appdata%\Programs\Zero Install or %ProgramFiles%\Zero Install. Then it creates a start menu entry, adds the directory to the command-line PATH and installs the Store Service.

This is slightly different from the desktop integration Zero Install performs for other applications. For these Zero Install will create little stubs in the appropriate locations that point to the application’s feed. However, for Zero Install itself instead of stubs a complete copy needs to be created. Otherwise these stubs would need to bundle all the functionality of the Bootstrapper in order to choose and locate a specific Zero Install instance in the cache. A classic chicken or the egg dilemma.

Having a specific version of Zero Install copied to a fixed location would seem to undermine many of the advantages of Zero Install, such as background updates of applications and running multiple versions side-by-side. However, Zero Install can still download and run other versions of itself from the cache. When you tell your deployed instance of Zero Install to update itself it does just that: The new version is downloaded and launched from the cache and instructed to deploy itself to the same location as the existing deployment. The old files are securely replaced using the Windows Restart Manager and rollbacks in case of error.

The Bootstrapper is a .NET 2.0 executable. This means it will run out-of-the-box on Windows Vista (which comes with .NET 3.0 built in) and later. Even most of the Windows XP installs still out there have .NET 2.0, 3.5 or 4.0 installed.

In the next part we’ll look at how the Bootstrapper manages to be a GUI app and a command-line tool at the same time.

Posted in Blog