It's All About AppStart.exe
As mentioned earlier, the Updater block comes with an application called AppStart.exe
which serves as a host process that loads configuration data, launches your application, and invokes the Updater block code to do its work. This means that, instead of launching your application directly, you need the user to launch AppStart, which in turn will locate and load your application's .exe
file using configuration data from the AppStart assembly's app.config
|Figure 1. Updater Directory Structure: You must install your application with a specific directory structure for the Application Update Block to work properly.|
This might seem a little strange at first, but it's necessary so that polling and downloads can run in a process separate from that of your application, letting users continue using your application without being interrupted.
For this to work, you need to ensure that your application has a very specific directory structure. You install AppStart and the Updater assemblies in the root of your application's folder hierarchy (see Figure 1). You install your application's files in a subfolder; you can give the subfolder any name you like, but note that Microsoft recommends that you give it the same name as the initial version of your application (see Figure 2).The reason for this will become clear shortly.
For the update process to work, any shortcuts to your application must point to AppStart.exe, and not directly to your application. The best way to ensure this is to create an application installer that builds the correct directory structure and creates the relevant shortcuts.
Creating an Application Installer
|Figure 2. Application Directory Structure: During the installation, place your application's files in a directory named according to the current version of your application.|
You need to create an installer that will reproduce the correct file structure and shortcuts on your users' machines. To do this:
- Add a Setup project to your solution;
- Select the new project in the Solution Explorer, and select View | File System;
- Add the Primary Output and Content Files from AppStart to the Application Folder for the target machine. Because AppStart references the Updater and Exception Management block assemblies, the installer will pull these into the folder as well (see Figure 3).
|Figure 3. Setup Project: Add the Primary Output and Content Files from AppStart to the Application Folder for the target machine.|
You then need to create the subfolder for your application files:
- Right-click the Application Folder and select Add | Folder;
- Change the new folder's name to "22.214.171.124";
- Select the folder and choose Add | Project Output from the context menu;
- Select your Windows Forms application project, and ensure that Primary Output is selected (see Figure 4).
|Figure 4. Installation Application Folder: In the install project, create a folder named the same as your application's version number, and add the Primary Output from your project to that folder.|
The installer will create a "Company Name\Product Name" directory structure under your user's Program Files directory. To ensure that the installer creates correctly named folders:
- Select the setup project in the Solution Explorer;
- Change the Author property to the name of your organization;
- Change the Product Name from its default setting (the name of the setup project) to the name of your application.
After following these steps, you need to create the shortcuts that your user will use to launch AppStart:
- Select the Primary output for your Windows Forms application;
- Choose Create Shortcut from the context menu;
- Rename the shortcut to something appropriate, and drag it into the User's Desktop and User's Programs Menu folders (if these aren't visible, then add them by choosing the appropriate folders from the context menu). Figure 5 shows how your Setup application should look.
|Figure 5. Creating Shortcuts: Rename your shortcut appropriately and drag it into the User's Desktop and User's Programs Menu folders in the Setup project.|
Build and test the installer by selecting "Install" from the installer project. If you double-click one of the shortcuts created during the installation, you'll find that not much happens; if you are very
lucky, after a short interval your application will load. Otherwise, you'll just get an exception indicating that AppStart has not been configured correctly.