Deploying Windows Applications
This section details how to create an installer to distribute a simple reporting application.To get started, we need a simple reporting application to play around with. For our walk-through, we are going to use the sample Windows project that can be found within the downloadable files for this chapter. In the download files, there is a single solution file for this chapter (chapter10.sln) and within the solution file, there is a project called ch10_app, which contains a sample application that we will be using to demonstrate distributing a Windows application.
The application consists of a single form that hosts the Windows Crystal Report Viewer and when run will display a preview of an Employee Listing Report, as shown below:

Creating a New Setup Project
As we stated earlier, to create a new Setup Project for an application, select File | Add Project | New Project and open the Setup and Deployment Projects folder and select Setup Project from the available templates. To keep things simple, we have already created the one for our application, and have called the setup project ch10_Setup.This will open the design environment and the File System Explorer, shown in the following screenshot, which we will come back to:

For now, we will see how to set some basic properties for our setup project - select View | Properties Window and then in the Solution Explorer, click on the name of your setup project, which will open the property page shown below:

As you can see there are a number of properties available. We won't change any of them here, but the most commonly used ones are:
Author
Manufacturer
Product Name
Version
The Product Name property controls how your application will be advertised on the Add/Remove Programs menu in Control Panel, and other properties are also used for registry entries, and other application properties.Anywhere you see a property in square brackets (for instance, [Manufacturer]), it means that this property is being treated as a variable and its value will be inserted when the application setup is created.
Selecting Project Outputs
When you first create the setup project, the IDE is opened to show the File System Explorer:

The File System Explorer is used to add the various types of files (.exe, .dll, .rpt) to your setup project, and when your setup program is run, the files will be copied to the location you specify.In the File System Explorer, the majority of files from your project will be targeted at the Application Folder. By default, any items added to this folder will be copied to drive:\[ProgramFilesFolder]\[Manufacturer]\[ProductName], but you can change this default, if you like, by editing the respective properties in the Properties dialog.To add files to the Application Folder, you would click on it and select Action |Add | Project Output - again this has already been done for this example. This will open the dialog shown below and allow you to add a Project Output Group.

If you select Primary output, this will add the primary EXE and DLL files from your application. You would need to repeat the process and select Content Files to actually pick up the report files within your application.
Determining Runtime File Requirements
With the main components of your application added to the setup project and all of the report files as well, you would now need to determine what runtime files are required to make those same reports work on the target machine.When looking at the runtime file requirements for Crystal Reports, there are a number of considerations, including the data source for your report (and any drivers in use), and export formats you wish to support, among other things.
There are three different types of merge files that can be used to help you determine these requirements:
Managed.msm - The managed component MSM handles the distribution of all the managed components, which include the Windows Form Viewer, Web Forms Viewer, and all of the Crystal Decisions namespaces.
Database_Access_enu.msm - The database access MSM handles the distribution of all of the other files that are needed to get the reports to run. This includes the database, export, and charting drivers.
Regwiz.msm - Handles the installation of the Crystal Decisions keycode, so that your users are not asked to register their versions of Crystal Reports when viewing reports.
Important
In the documentation for Crystal Reports.NET, the regwiz.msm module is referred to as keycode.msm and it also mentions there are 19 different merge modules available for Crystal Reports.NET - all of these modules are iterations of the same merge modules to support additional (human) languages.
These merge files will do most of the work for you when deciding what files should be included in your setup program, but you should always double-check the files that the merge module has specified, just to make sure they have them all.
Adding Merge Modules
If you look in the Solutions Explorer under your setup project, these modules will appear in one of two places. If your setup project has detected a dependency that has already been detected (from the files you added earlier), the corresponding merge module can be found in the Detected Dependencies folder, as shown below:

If the merge module you require hasn't been automatically detected, you can add a merge module to your setup project by selecting Project | Add | Merge Module and browsing for the merge module you want using the dialog shown here:

Select the merge module you want to add and click Open to add the module to the list.If you would like to see what files are included with a module, view the Properties and check out the Files property, shown here:

You can also see any dependencies that a module has by viewing the ModuleDependencies property, which will give the dialog below:

Working with Licensing
One of the requirements for using Crystal Reports.NET and distributing the free runtime and reports with your application is that you register the software and your personal details with Crystal Decisions. What better way to enforce registration than with a nag screen that appears whenever you open the report designer (charming, I know!).In order to successfully distribute your application and get rid of the nag screen, you are going to need to register with Crystal Decisions and obtain a registration number. When you first started the Crystal Reports designer, chances are you were prompted to register at that point.If you just clicked Cancel (like most people) you can still register by opening the Report Designer, and selecting Register from the right-click menu, which will open the dialog shown below:

If you have registered, we need to take the registration number you were given and enter it into the Regwiz.msn merge module.To copy your registration number (or to find out if you are registered), select Help | About Microsoft Development Environment to display a list of all of the Visual Studio .NET products you have installed.

Note the registration number (or to do it the easy way, highlight Crystal Reports.NET and click on the Copy Info button). From that point, click OK to return to your project and locate the License Key property under Regwiz.msm merge module. You will need to enter or paste this license key before you build your setup project.

This is one of the most common errors when deploying applications that use Crystal Reports, so don't forget to do it every time you create a setup project.
Building your Setup Project
The last step of creating our setup project is to actually build the setup project. To build your setup, select Build | Build Ch10_Setup and keep an eye on the Output window.
Important
The default Project Configuration is Debug and Projectname is the name of the deployment project - in our instance, if you had unzipped the sample files for this chapter into a CrystalReports directory on your machine, the setup directory would be found at C:\CrystalReports\Chapter10\code\setup_wizard\Debug.
Along with the MSI file that has been generated, there are also some additional files that should be in the same directory:
setup.exe - serves as a wrapper for the .MSI file that has been created and for a utility that verifies the correct Windows Installer version and installs the correct version
setup.ini - an .ini file containing the location of the Windows Installer files
Instmsia.exe - the Windows Installer files for Windows 95, 98, and ME
Instmsiw.exe - the Windows Installer files for Windows NT
If the setup finds that Windows Installer is not present or the correct version, it will launch the correct executable (Instmsia.exe or instmsiw.exe) to install or update the Windows Installer service before installing your own application.
Testing and Deploying your Setup Project
To test your generated deployment package, copy the entire directory to another computer or CD and run the setup.exe file, as shown here:

To test your application set up, you should be able to see where your files were installed and verify that they are present. Also, the application should appear under the Add/Remove Programs option in the Windows Control Panel.In addition, if you have added a shortcut to your application, you should be able to select the shortcut you have created and it should launch the application. Make sure that you test the reports themselves, viewing a number of different reports and trying out the features such as drill-down and exporting.Once you are satisfied that the application is installed and that it and the reports run correctly, you can distribute the setup files within the subdirectory to users as required.