C# Desktop Deployment Squirrel


This post summarizes most of the video by IAmTim that covers how to create a setup for your C# Windows project that uses SQLite and Dapper. The YouTube video is called C# Desktop App Deployment with Squirrel – Easier than MSI Files, Better than ClickOnce. In the video he shows us how to create an application installer and an application updater.

At time 3:45 Tim begins to talk about Squirrel. He says the MSI and EXE files that get created with MSI installer and Click Once are not that easy to create. Squirrel is easier, but you sacrifice some of the edge use cases (fancy options). Also if you want the full-featured version you might have to pay for that.

Right-click on References of the project in Solution Explorer (on the right side) and choose Manage NuGet packages. Click Browse and enter Squirrel to locate squirrel.windows. The latest version as of December 2020 is 2.01. Click the install link. Once it has finished installing you can close the package manager.

Next we need to create a place where the update runs. In your code-behind, create a new method just under the public MainWindow() method. Call it CheckForUpdates. This is just our test version here because normally you would not be using a local drive like I am. You might even be pointing out to a GitHub location where you would store your updates. I have shown the location to be C:\MyProjects\MySquirrelDem0\ as an example. Yours will likely be differrent

private async Task CheckForUpdates()
{
    using (var manager = new UpdateManager(@"C:\Projects\MySquirrelDemo\SquirrelReleases"))
    {
        await manager.UpdateApp();
    }
}

You’ll also want the using statement as shown here.

using Squirrel;

Go over to Properties and scroll down to the bottom to change the assembly version. Change it to the following so that there are two zeros, not three.

[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]

Now we need to create our own NuGet package. This is what Squirrel uses for the updates. Tim begins to discuss this at time 18:30 in the video. He uses the NuGet Package Explorer. Google it and download it. It is in the Microsoft Store. Run it. In the list of Common Tasks, click Create a New Package (Ctrl+N). The interface now has a left and right side. In the left pane click the small icon to begin editing. Fill out the Id, Version, Authors, and Description sections to something more appropriate than what is already suggested. The Id is the name of the application, without having any spaces. Click the green checkmark to save it.

Now we need to add package contents. Before dragging files and folders over to the right side, right-click on the right side and choose Add New Folder and call it lib. Right-click on lib and add another folder by choosing Add New Folder. Call it net45. As an aside, a pdb file is a file in our C# project that contains debugging information. We don’t want these files to be released.

At time 34:05 Tim illustrates how to use Reflection in C# to get and display the version number of your application. If you are developing in WPF, use “this.Title” instead of “this.Text”.