2011年11月7日 星期一

Deploying A C# Application (Visual Studio Setup Project)

In this tutorial I will show how to deploy a C# application using a standard Visual Studio Setup Project.

Any application must be somehow provided to the end-user. If the application is very small and is composed of a single executable, it can be deployed by just providing the executable to the end user. In our situation, the application has many dependencies, that can or cannot be present on the client machine, so we need to create a setup project, that will install the needed dependencies and the application itself.

Special Tutorial Requirements:

  • Microsoft Visual Studio 2008 ('Setup and Deployment' projects are not available in Express editions)

Let's start.

1. First of all we need to open a C# project/solution (or any other project/solution you have made using one of the programming languages included in Visual Studio). Use 'File -> Open -> Project/Solution' (or Ctrl+Shift+O):

Posted Image

Resized to 82% (was 610 x 480) - Click image to enlargePosted Image


2. After opening a C# project/solution you will get something like this:

Resized to 49% (was 1024 x 733) - Click image to enlargePosted Image


3. Now you have to add a setup project to the current solution. Use 'File -> Add -> New Project...':

Resized to 100% (was 502 x 385) - Click image to enlargePosted Image


4. In the 'Project types' list, go to 'Other Projects -> Setup and Deployment' and select the 'Setup Wizard' template:

Resized to 63% (was 804 x 512) - Click image to enlargePosted Image


As you see there are many 'Setup and Deployment' project types and you can create just a blank setup project and customize it by yourself, but in this tutorial I will show how to use the wizard, which is a little bit easier for beginners.

5. Now let's take a deeper look at the wizard.

The wizard is composed of 5 general steps:

Step #1: Initialization

Resized to 76% (was 658 x 505) - Click image to enlargePosted Image


This step is a 'welcome message'.

Step #2: Project Type

Resized to 76% (was 658 x 505) - Click image to enlargePosted Image


In this window you have to select the setup project type. You have four options:

To create a setup program to install an application:
  • Create a setup for a Windows application
  • Create a setup for a web application


To create a redistributable package:
  • Create a merge module for Windows Installer
  • Create a downloadable CAB file

I will use the 'Create a setup for a Windows application', as my C# project is a Windows application.

Step #3: Project Outputs

Resized to 76% (was 658 x 505) - Click image to enlargePosted Image


Here you must select the project outputs you wish to include in your installation package. For my project I select only 'Primary output', which includes the application DLL or EXE.

Resized to 76% (was 658 x 505) - Click image to enlargePosted Image


Step #4: Files to include

Resized to 76% (was 658 x 505) - Click image to enlargePosted Image


Here you have the opportunity to add additional files, like guides, HTML pages or just a ReadMe file. I will add just a ReadMe file:

Resized to 76% (was 658 x 505) - Click image to enlargePosted Image


Step #5: Confirmation

Resized to 76% (was 658 x 505) - Click image to enlargePosted Image


Here you can see the settings for the project that will be created. If you find a mistake or something, you can easily go back and change a specific setting.

6. If the project was successfully created, you will see this:

Resized to 49% (was 1024 x 768) - Click image to enlargePosted Image


7. Now you can customize the setup project properties. To access the project properties grid, click on Setup1 project in the 'Solution Explorer' window:

Here are the properties and a short explanation of what they do:

AddRemoveProgramsIcon - Specifies an icon to be diplayed in the Add/Remove Programs dialog.
Author - Specifies the name of the author of an application or component.
Description - Specifies a free-form description for an installer.
DetectNewerInstalledVersion - Specifies whether to check for newer versions of an application on the user's computer.
InstallAllUsers - Specifies whether the package is installed for all users or only the current user.
Keywords - Specifies keywords used to search for an installer.
Localization - Specifies the locale for string resources and the run-time user interface.
Manufacturer - Specifies the name of the manufacturer of an application or component.
ManufacturerUrl - Specifies a URL for a Web site containing information about the manufacturer of an application or component.
PostBuildEvent - Specifies any commands to execute after the build ends.
PreBuildEvent - Specifies any commands to execute before the build starts.
ProductCode - Specifies a unique identifier for an application.
ProductName - Specifies a public name that describes an application or component.
RemovePreviousVersions - Specifies whether an installer will remove previous versions of an application or component.
RunPostBuildEvent - Specifies the condition under which the post-build event runs.
SearchPath - Specifies the path that is used to search for assemblies, files or merge modules on the development computer.
Subject - Specifies additional information describing an application or component.
SupportPhone - Specifies a phone number for support information for an application or component.
SupportUrl - Specifies a URL for a Web site containing support information for an application or component.
TargetPlatform - Specifies the target platform of the installer.
Title - Specifies the title of an installer.
UpgradeCode - Specifies a shared identifier that represents multiple versions of an application or component.
Version - Specifies the version number of an installer, merge module, or .cab file.

8. You can also specify what folders to create on the desktop and in the Start menu:

Resized to 64% (was 789 x 445) - Click image to enlargePosted Image


9. You can also customize the entries that will be added to the registry:

Posted Image

Resized to 63% (was 795 x 445) - Click image to enlargePosted Image


10. You can also customize the file types on the target machine:

Posted Image

Resized to 64% (was 793 x 445) - Click image to enlargePosted Image


11. You can also customize the user interface of the installer:

Posted Image

Resized to 63% (was 795 x 447) - Click image to enlargePosted Image


You can add additional dialogs:

Posted Image

12. You can also customize the custom actions:

Posted Image

Resized to 63% (was 795 x 447) - Click image to enlargePosted Image


13. You can also customize the launch conditions:

Posted Image

Resized to 63% (was 795 x 447) - Click image to enlargePosted Image


14. When you're done with project customizations, build the project (right click on 'Setup1', then select the 'Build' option):

Posted Image

Now you've got a new installation package for your application or component.

This tutorial showed the basics of creating a setup project, so now you can easily deploy your applications to the end-user.

沒有留言:

張貼留言