Tuesday, May 24, 2016

Using Squirrel to replace ClickOnce

Installing Squirrel

While I was searching for a way to make ClickOnce deploy easier after all hardship about certificate and identity errors, I bump into Squirrel.Windows. Thanks to Travis's comment in this question: Deploy a ClickOnce application without signing. Even though no one answer that was Marked ans Answer (yet at the time), the comments really help to give me an idea about some alternatives.

I create a new project that target a .Net Framework 3.5 and start searching for it in the Manage Nuget Packages for Solution.Current latest stable version is 1.4.0. I install it right away.



Got an error with some of it's dependencies:
Could not install package 'DeltaCompressionDotNet 1.0.0'. You are trying to install this package into a project that targets '.NET Framework,Version=v3.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
and this:
Could not install package 'Splat 1.6.2'. You are trying to install this package into a project that targets '.NET Framework,Version=v3.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I can install latest DeltaCompressionDotNet 1.1.0 manually but it seem that Splat 1.6.2 (currently latest) can only be installed on the project that targetted the .Net Framework 4.5.0 and above.

So bye bye project for Windows XP. A little bit disappointed because my company still using Windows XP in some machines.

I change my target.Net Framework to 4.5.0 and it installed successfully.




Time to read the Getting Started Guide.

By the guide, I must insert a new Class name Program. This is the code for the Class:

Imports Squirrel

Namespace MyApp

    NotInheritable Class Program

        Private Sub New()
        End Sub

        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        <STAThread>
        Private Shared Async Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Application.Run(New Form1())

            'The following code is added to cause the application to check for, download
            'and install any New releases of App in the background while you use the application.
            Using mgr = New UpdateManager("D:\Releases")
                Await mgr.UpdateApp()
            End Using

        End Sub
    End Class

End Namespace



I made the Directory "D:\Releases" as a place to put my build program. And that the place the program install and search for update.

Creating a Nuget Package

In the guide in Step 2. seem like I have to install Nuget Explorer to package my program. Here's the installer: Nuget Explorer for Windows. If uses Internet Explorer, it will run immediately.


This is when I run it:


1. I just have to create a new package (Ctrl+N).

2. Then Edit Metadata:
Edit Metadata - update package metadata for MyApp.
  • Id - name of the application (no spaces)
  • Version - version specified in Properties\Assembly.cs
  • Dependencies - Squirrel expects no dependencies in the package (all files should be explicitly added to the package)

3. Add lib & net45 - add the lib folder and the net45 folder to the project. Squirrel is expecting a single lib / net45 directory provided regardless of whether your app is a net45 application.


4. Add Release Files - add all the files from Release needed by the app to execute (including the various files required by Squirrel).
Include MyApp Files: MyApp.exe, MyApp.exe.config, any non-standard .NET dll's needed by MyApp.exe.
Include Squirrel Files: Squirrel.dll, Splat.dll, NuGet.Squirrel.dll, Mono.Cecil.*, DeltaCompressonDotNet.*, ICSharpCode.SharpZipLib.*
Exclude: .vshost.\, *.pdb files
This is the picture from the guide:

5. Save the NuGet Package File - save the NuGet package file to where you can easily access later (e.g., MyApp.sln directory). Follow the given naming format (e.g., MyApp.1.0.0.nupkg).


Using Releasify


I can use the Squirrel.exe tool that was included in the Squirrel.Windows package you installed in the MyApp.sln previously.

Use the Package Manager Console to execute Squirrel.exe --releasify command.



Looks like the rott directory for Package Manager Console is the active Solution (sln) directory. So I can just run the command:
PM> Squirrel --releasify SquirrelTest.1.0.0.nupkg

Tip: If you get an error stating that ...'Squirrel' is not recognized... then you may simply need to restart Visual Studio so the Package Manager Console will have loaded all the package tools.

After running the command, I realize a new folder named "Releases" created in my solution directory. 


And this is the content:

Note from the guide:
  • Create Releases Directory - creates a Releases directory (in the MyApp.sln directory by default).
  • Create Setup.exe - creates a Setup.exe file which includes the latest version of the application to be installed.
  • Create RELEASES File - creates a file that provides a list of all release files for MyApp to be used during the update process
  • Create MyApp.1.0.0-full.nupkg - copies the package you created to the Releases directory.
  • Create MyApp.*.*.*-delta.nupkg - if you are releasing an update, releasify creates a delta file package to reduce the update package size (see Updating for details).

Distributing

Note from the guide:

After packaging MyApp for distribution, the various files in the Releases directory are used to distribute MyApp to users.
  • Setup Application - the Setup.exe application is provided to new users to install the current version of MyApp (see Installing for details).
  • Update Files - the RELEASES file, along with versioned full and delta packages, are used by the update process (see Updating for details).

Installing

To install, just have to run the Setup.exe generated by the Package Manage Console in the Releases folder.

Updating

To update my app, I have to update the assembly version.


Properties\AssemblyInfo.cs[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
 Then build my app at the Release mode then build the app.

Repacking

Follow it from the guide:
  1. Open Previous NuGet Package - open the previous NuGet package you created for MyApp version 1.0.0.
  1. Update Version - update the version in the metadata.
  1. Replace Release Files - replace the changed files under lib\net45. You can simply drag and drop any program specific files that have changed (i.e., the MyApp.exe file is the only one that has updated in the example).
  1. Save the NuGet Package File as New Version - use the "Save As..." feature to save the new version of the packageMyApp.1.0.1.nupkg.
After building the apps. reopen the Nuget Package Explorer. Get the only updated files into the net45 folder. In my case, only the .exe file is updated so I should only put the .exe file into the net45 folder.


This is my result:

Save the package. the package name should increment by version:

Then releasify the new package:
PM> Squirrel --releasify SquirrelTest.1.0.1.nupkg
If error, just restart the Visual Studio then run the command again.

This is the result:







No comments:

Post a Comment