Squirrel.Windows Documentation
repository·develop·Indexed 27 days ago
https://github.com/squirrel/squirrel.windowsA toolset and library for managing the installation and background updating of Windows desktop applications. Squirrel.Windows provides a seamless, wizard-free experience and is language-agnostic, supporting both C# and native C++ applications. It leverages NuGet packages for distribution and includes tools for packaging (releasify), distributing via platforms like GitHub, IIS, or Amazon S3, and managing the update lifecycle through the UpdateManager API.
What's inside Squirrel.Windows
- Squirrel is a set of tools and a library designed to manage the complete lifecycle of Desktop Windows applications, including installation and updating. It is language-agnostic; while it supports C#, it can also manage native C++ applications. Squirrel leverages NuGet packages to create installation and update packages, making the packaging process familiar to many developers.
How the UpdateManager performs application updates
developThe
UpdateManager(configured during integration) handles background updates automatically each time the application is executed.The update workflow is as follows:
- Check: The
UpdateManagerchecks theRELEASESfile at the specified distribution location for any new versions. - Download & Prepare: If an update is found, the necessary update packages are downloaded and the new version of the application is prepared.
- Cleanup: App shortcuts are updated to point to the new version, and old version files are cleaned up.
User Experience:
- The first time the user runs the app after an update is available, the app runs the old version normally.
- The update happens in the background.
- The next time the user executes the application, they are running the newly installed version.
- Check: The
Understand the Squirrel installation process and file structure
developWhen
Setup.exeis executed, it performs the following steps:- Creates a directory for the application under
%LocalAppData%\MyApp. - Extracts and prepares the application files into a versioned directory named
app-x.x.x(e.g.,app-1.0.0). - Launches the main application executable (e.g.,
app-1.0.0\MyApp.exe) once the setup is complete.
The final installation resides in the
%LocalAppData%\MyAppdirectory.- Creates a directory for the application under
Understand the Setup.exe bootstrapper
developThe
Setup.exeis a C++ bootstrapper application generated during theSquirrel --releasifyprocess. It serves as the entry point for installing your application on a user's local system.Key characteristics:
- It bundles the
Update.exeapplication and the latest version of your application package into a single executable. - It automatically ensures that .NET 4.5 is installed on the user's machine.
- It uses the
WriteZipToSetup.exetool to inject necessary files into the single executable.
- It bundles the
Overview of the Squirrel.Windows integration workflow
developTo use Squirrel.Windows for distributing and updating a Windows application, you must follow these five primary steps:
- Integrating: Incorporate the Squirrel
UpdateManagerinto your application code. - Packaging: Package your application files and prepare them for release.
- Distributing: Provide the necessary install and update files to your users.
- Installing: Manage the initial installation process of your application.
- Updating: Manage the process of updating an existing installation.
- Integrating: Incorporate the Squirrel
Generate a Delta Package
developTo create a Delta package from a full NuGet package, you must replace existing binary files (DLLs/EXEs) with
bsdiffpatches to reduce package size. Follow these steps:- Extract the previous NuGet package.
- Extract the current NuGet package.
- For every EXE/DLL in the current package, replace it with a
bsdifffile. For example,lib\net40\MyCoolApp.exeshould becomelib\net40\MyCoolApp.exe.diff. - For each replaced file, create a
.shasumfile (e.g.,lib\net40\MyCoolApp.exe.shasum) containing the SHA1 hash of the expected resulting file and its file size. This file follows the same format as the 'Releases' file used in the 'Latest' Pointer section. - Include any new DLLs from the current package verbatim.
- Zip the resulting directory back into a package.
Integrate Squirrel packaging into Visual Studio build process
developYou can automate the creation of NuGet packages and Squirrel release files by adding an
AfterBuildtarget to your.csprojfile. This target extracts the assembly version, runsnuget packto create a.nupkgfile, and then runssquirrel --releasifyto generate the final release assets.Ensure that
nuget.exeis available in your environment (e.g., by installing theNuGet.CommandLinepackage) and thatsquirrel.exeis in your system PATH.<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'"> <GetAssemblyIdentity AssemblyFiles="$(TargetPath)"> <Output TaskParameter="Assemblies" ItemName="myAssemblyInfo"/> </GetAssemblyIdentity> <Exec Command="nuget pack MyApp.nuspec -Version %(myAssemblyInfo.Version) -Properties Configuration=Release -OutputDirectory $(OutDir) -BasePath $(OutDir)" /> <Exec Command="squirrel --releasify $(OutDir)MyApp.$([System.Version]::Parse(%(myAssemblyInfo.Version)).ToString(3)).nupkg" /> </Target>Understand the Squirrel Update Process
developThe
UpdateManagerautomatically performs the following steps every time your application is executed:- Check for Updates: Downloads the
RELEASESfile from the distribution location and compares it to the localRELEASESfile. - Download & Verify Update Packages: Determines whether to download delta packages or the latest full package based on which requires less total downloading. Packages are verified against their SHA1 hash specified in the
RELEASESfile. - Build Full Package from Deltas: If delta packages were used, a new full package is constructed from the existing full package and the downloaded delta.
- Install New Version: Extracts the new version into a new
%LocalAppData%\MyAppdirectory named after the version (e.g.,app-1.0.1). - Update Shortcuts: Updates desktop and Windows Start Menu shortcuts to point to the new version using the
--processStartcommand line parameter passed toUpdate.exe. - Previous Version Clean-up: On the subsequent startup of the application, Squirrel deletes all versions except for the current version and the immediately preceding version (e.g., if updated to
app-1.0.5,app-1.0.4is kept, butapp-1.0.3and older are removed).
- Check for Updates: Downloads the
Distribute Squirrel updates via GitHub Releases
developTo distribute your
RELEASESfile and NuGet update packages using GitHub, follow these steps for every release:- Commit Latest Code: Ensure you have at least one additional commit since the last release tag. GitHub will not mark a new release as
Latestif the tag points to the same commit as a previous release. - Create a New Release: Create a new GitHub release matching your current version (e.g.,
1.0.0). - Upload Release Files: Upload all necessary files from your
Releasesfolder as assets for that specific release. This includes:- The
RELEASESfile - Full packages (e.g.,
MyApp.1.0.0-full.nupkg) - Delta packages (e.g.,
MyApp.1.0.1-delta.nupkg)
- The
- Set Pre-release (optional): Mark the release as a pre-release if desired.
- Publish the Release.
Important: You must upload all packages as assets for the release. The
GitHubUpdateManagerdoes not look back at previous GitHub releases for older version packages. If you only upload the latest packages, Squirrel will be forced to download the latest full package for every update instead of using efficient delta updates.- Commit Latest Code: Ensure you have at least one additional commit since the last release tag. GitHub will not mark a new release as
Catch and log UpdateManager exceptions
developTo debug the update process in your application, wrap the
UpdateApp()call in a try-catch block to capture and log any thrown exceptions.using (var mgr = new UpdateManager("C:\\Projects\\MyApp\\Releases")) { await mgr.UpdateApp(); }Distribute MyApp using Squirrel releases
developOnce your application is packaged, the
Releasesdirectory contains the necessary files for distribution:- New User Installation: Provide the
Setup.exefile to new users to install the current version of your application. - Updates: The update process requires the
RELEASESfile along with the versioned full and delta packages to perform updates.
- New User Installation: Provide the
Add Squirrel packaging to TeamCity
developTo automate the creation of release packages within a TeamCity build pipeline, you can use the
squirrelexecutable to run the--releasifycommand. This process converts a.nupkgfile (generated from a.nuspecfile) into the final release format.- Ensure your solution includes Squirrel via NuGet so that
squirrel.exeis available in thepackagesdirectory. - Add a NuGet Pack process to create the
.nupkgfile. - Add a command line build step using the following command structure:
%system.teamcity.build.workingdir%\packages\squirrel.windows.1.4.0\tools\squirrel --releasify [BUILD_SERVER_NUPKG_PATH]\%system.build.number%.nupkg -r [OUTPUT_PATH]Note: You must update the paths to match your specific project structure and the exact version of the
squirrel.windowsNuGet package you are using.- Ensure your solution includes Squirrel via NuGet so that