Visual Studio 2005 Application Distribution


This article discusses two different ways of distributing a basic Win32 C++ application, built with Visual Studio 2005, to client computers via web distribution. The application primefactors.exe is a basic console application for factoring or listing primes in the unsigned long long (64 bit) range (maximum number 18,446,744,073,709,551,615 = 2^64 - 1).

Method 1: Compile and link statically using /MT (Win98 - XP)

The simplest possible deployment strategy for a basic Win32 application involves compiling the application as a Win32 application, and moving the .exe application (or library dll) to a web server and providing end users with the download link information, typically via a web-page link as done here. The default C++ compiler option for runtime libraries in Visual Studio 2005 is /MD which causes a dependency at run time on the DLL MSVCR80.dll which will not be installed typically on clients. Statically linking with /MT, which links using the static multithreaded library LIBCMT.lib, while not recommended due to maintenance issues, can make sense in simple cases. The compiled application will obviously be larger than linking to a dll (as discussed below), but has the advantage of being self-contained and allowing installer-free deployment targetting many downlevel systems.

Primefactors.exe (statically linked; 133 kb; digitally signed)

Method 2: Compile and link dynamically using /MD (W2k sp4 +)

The second version of deploying primefactors.exe uses a Visual Studio 2005 Setup/Deployment project. The project was compiled with the /MD compiler option and so will require the MSVCR80.dll library installed on the client machine which means that minimally the Microsoft.VC80.CRT shared assembly must be installed. It is possible to build the application and Setup project using Merge Modules dependencies, but to ensure that C++ libraries are installed only once, and the application msi installer is as small as possible, a "Prerequisites" approach is used. This means that if further applications are deployed, they can be minimized in size, since the dependent CRT libraries will already be installed. To ensure that the client can run the installer and also that the Microsoft Visual C++ Libraries are installed (CRT, ATL and MFC although the current application only requires the CRT assembly) the project was built with two Setup application "Prerequisites" conditions: If the download client platform does not have the Windows Installer 3.1 or the required Visual C++ runtime libraries already installed, they will be downloaded and installed (once only) from the same web server as the main application installer, but in a different directory specified in the "Download Prerequisites from the following location:" http://www.jensign.com/prereq/.
If the C++ Libraries and Windows Installer 3.1 are already installed, the application bootstrapper and installer downloads will be the only downloaded files and are as small as possible.

Sizes of components:
primefactors.exe (12 kb installed in C:\Program Files\JavaScience Consulting\PrimeFactors folder)
setup.exe (357 kb),
SetPrimeFactors.msi (97 kb),
vcredist_x86.exe (2.52 Mb) (Prerequisite only installed if necessary)
WindowsInstaller-KB893803-v2-x86.exe (2.46 Mb) (Prerequisite only installed if necessary)

The application bootstrapper file setup.exe and installer file SetPrimeFactors.msi were both digitally signed and time-stamped as a PostBuildEvent script, using a 2048 bit self-signed certificate created using makecert. The Setup project had the "Installation URL:" field in the setup project Property Pages set to http://www.jensign.com/primes/ so that the bootstrapper file can access the installer .msi file from the same web directory.

After the setup project is built, the following output files are moved to the web server specified by the Installation and Prerequisites URLs above: setup.exe, SetPrimeFactors.msi and the folders vcredist_x86\vcredist_x86.exe (which is the Microsoft Visual C++ Libraries redistributable) and WindowsInstaller3_1\WindowsInstaller-KB893803-v2-x86.exe. If the user chooses to run the application installer (after all prerequisites are installed if necessary), there are 2 consecutive and similar warnings messages presented to the user, which allows the user to make a security decision, based on trust of the source of the application, and perhaps based on the digital signature information. This is followed by an install directory configuration dialog.

The installer is built to add a desktop icon for primefactors.exe and adds a Start Menu | All Programs entry. The application is registered with this installation approach and can be removed using the "Add or Remove Programs" control panel. To download and start running the PrimeFactors installer, select this link:
Setup.exe
(Note that since the .exe and .msi were signed with a self-signed certificate, the dialogs will warn of that status.)



See also: Walkthrough: Deploying a Windows-based Application