How to Package C # Program (make it into an installer)

Source: Internet
Author: User

Create a new installation project
  1. On the File menu, point to add and click Create project ".

  2. In the "Add new project" dialog box that appears, open the "other project type" node and select the "Install and deploy project" folder.

  3. In the template pane, select "installation project" (Standard installation) or "Web installation project" (Web installation ).

Add an existing installation project to the solution
  1. On the File menu, point to add and click existing project ".

  2. In the "add existing project" dialog box that appears, browse to the location of the installation project and click "open ".

 

I can't tell you a few words, just give you msdn :)
This walkthrough demonstrates how to create an installer for a Windows application that starts notepad. In this walkthrough, you will first create a Windows application and then an installer; this allows you to set shortcuts and file associations, add registry keys, display custom dialog boxes, and check Internet Explorer versions during installation.

Note that you do not need to perform all the following steps when creating your own installer. The purpose of this walkthrough is to introduce some optional functions that may be used during deployment. To create a basic installer, you only need to complete the first four parts of the installation process.
Create a Windows Application

On the "file" menu, point to "new" and select "project ".
In the Create Project dialog box, select Visual Basic Project in the project type pane, and select windows application in the template pane ". In the "name" box, type "my notepad ".
This project is added to Solution Explorer and the Form Designer opens.

In the toolbox, select the Windows Forms tab and drag the button control to the form.
Double-click the button control to add an event handler for the button. Add the following code to the event handler:
Shell ("notepad.exe", appwinstyle. normalfocus)
This will start notepad.exe and focus on it.

On the "generate" menu, select "generate my notepad" for this application.
Create a deployment project

On the "file" menu, point to "add project" and select "new project ".
In the Add new project dialog box, select "Install and deploy Project" in the "project type" pane, and select "Install Project" in the "template" pane ". In the "name" box, type "my notepad installer ".
The project is added to Solution Explorer and opened in the file system editor.

In Solution Explorer, select the my notepad installer project. In the "properties" window, select the productname attribute and type "my notepad ".
Note that the productname attribute determines the name of the application displayed in the folder name and the "Add/delete programs" dialog box.
Add a Windows application to the installer

In Solution Explorer, select the my notepad installer project. In the file system Editor, select the application folder node.
On the "operations" menu, choose "add"> "project output ".
In the Add project output group dialog box, select my notepad from the project drop-down list ".
Select the "primary output" group from the list and click "OK ".
On the "generate" menu, select "generate my notepad installer ".
Deploy the application (Basic installer)

Skip this step if you are performing a complete drill.

In Solution Explorer, select the my notepad installer project. Select "Install" from the "project" menu ".
This will run the installer and install "my notepad" on the development computer ".

The remaining steps demonstrate the optional deployment functions.

Create shortcuts for Windows Applications

This step creates a shortcut for your application. During installation, the shortcut is placed on the desktop of the target computer.

In Solution Explorer, select the my notepad installer project. In the file system Editor, select the "Master output from my notepad" node.
On the "operations" menu, select "create main output shortcut from my notepad (activity ".
This will add a "main output shortcut from my notepad (activity)" node.

Rename the "main output shortcut from my notepad (activity.
Select "main output shortcut from my notepad (activity)" and drag it to the "user desktop" folder in the left pane.
Create File Associations for Windows Applications

This step adds a file association for "My Notepad" to start the "my notepad" application when you double-click the. VBN file.

In Solution Explorer, select the my notepad installer project. On the "View" menu, point to "Editor" and select "file type ".
In the file type editor, select the file type node on the target computer. On the "operations" menu, select "add file type ".
A "New Document Type #1" node will be added, and the node will be open for you to rename.

Rename "New Document Type #1" to vbn.doc.
In the Properties window, set the extension attribute of the file type to VBN.
Select the command attribute and click the ellipsis. In the "select items in project" dialog box, locate "application folder" and select "main output from 'my notepad ".
Add a registry entry for a Windows Application

In this step, add a registry key and corresponding values to the Registry. During running, you can reference this registry key from the application code to retrieve information about each user.

In Solution Explorer, select the my notepad installer project. On the "View" menu, point to "Editor" and select "Registry ".
Select the "HKEY_CURRENT_USER" node, expand it, expand the "software" node, and select the "[manufacturer]" node.
Note that the "manufacturer" node contains parentheses, which indicates that it is an attribute. It will be replaced by the manufacturer attribute value of the input deployment project.
On the "operations" menu, choose "New"> "key ".
Rename the userchoice key.
On the "operations" menu, select "new", and then select "string value ".
Rename the textcolor value.
In the "properties" window, select the Value Attribute and Enter black.
Add custom installation dialog box

In this step, add and configure a Custom User interface dialog box displayed during installation.

In Solution Explorer, select the my notepad installer project. On the "View" menu, point to "Editor" and select "User Interface ".
In the User Interface Editor, select the Start Node under the "Install" node.
On the "operations" menu, select "add dialog box ".
In the Add dialog box, select check box ()".
On the "operations" menu, select "Move Up" twice, and place the "check box (a)" dialog box on the "Select installation folder" dialog box.
In the "properties" window, set the bannertext attribute to "example ".
Set the bodytext attribute to the "install sample file" check box to check whether the sample file is installed. If it is not selected, the example is not installed ."
Set the checkbox1label attribute to "do you want to install an example ?".
Set the checkbox2visible, checkbox3visible, and checkbox4visible attributes to false. This hides other check boxes.
Add samples folder

This step creates a samples sub-folder, which will be installed under the application folder.

In Solution Explorer, select the my notepad installer project. On the "View" menu, point to "Editor" and select "File System ". The "application folder" should still be selected.
From the "operations" menu, point to "add" and select "folder ".
Rename "new folder #1" as "example ".
Create a sample file for the Application

This step creates two simple text files. If you select the "installation example" option in the Custom dialog box, the two text files will be installed.

Use notepad or another text editor to create a text file containing the text "this is rules. VBN" and save it as rules. VBN.
Note: To prevent notepad from automatically adding a. txt extension, select "all files" from the "file type" drop-down list ".
Create another text file containing the text "this is Memo. VBN" and save it as memo. VBN.
Add the example to the installer

In this step, add the sample file to the samples folder and set the conditions to determine whether to install the file.

In Solution Explorer, select the my notepad installer project. From the "View" menu, point to "Editor", select "File System", and select the "example" folder.
From the "operations" menu, point to "add" and select "File ". Add the rules. VBN and memo. VBN files to the "example" folder.
In the file system Editor, select rules. VBN.
In the "properties" window, set the condition attribute to checkboxa1 = 1. When running the installer, the rules. VBN file is installed only when the custom check box is selected.
In the file system Editor, select the memo. VBN file.
In the "properties" window, set the condition attribute to checkboxa1 = 1. When running the installer, the memo. VBN file is installed only when the custom check box is selected.
Add startup conditions to check Internet Explorer versions

This step checks whether Internet Explorer 5.0 or later is installed on the target computer. If you do not install the required version of Internet Explorer, the installation process is stopped.

Note that this step aims to describe the concept of startup conditions; the "my notepad" application does not actually rely on Internet Explorer.
In Solution Explorer, select the my notepad installer project. On the "View" menu, point to "Editor" and select "Startup conditions ".
In the launch condition editor, select the requirement node on the target computer.
On the "operations" menu, select "add file startup conditions ".
A "Search for file1" node will be added under the "Search for target computer" node, and a "condition1" node will be added under the "Start condition" node.

Rename "Search for file1" to "Search for Internet Explorer ".
In the "properties" window, set the filename attribute to iexplore.exe, set the folder attribute to [programfilesfolder], set the depth attribute to 2, and set the minversion attribute to 5.00.
Select the "condition1" node.
Set the message attribute to "this program requires Microsoft Internet Explorer 5.0 or later. Install Internet Explorer and run the 'notepad 'installer again ."
Set the optional attributes of a deployment project

This step sets an attribute to automatically install the Windows Installation Guide file when no correct version of Windows Installer is available on the target computer.

In Solution Explorer, select the my notepad installer project. On the "View" menu, select "attribute page ".
On the "my notepad installer" property page, select the "Bootstrap" drop-down list and select "Windows Installer ".
On the "generate" menu, select "generate my notepad installer ".
Install "my notepad" on the development computer"

In Solution Explorer, select the my notepad installer project. Select "Install" from the "project" menu ".
This will run the installer and install "my notepad" on the development computer ".

Deploy my notepad on another computer

In Windows Resource Manager, locate the project directory and find the generated installer. The default path is/Documents and Settings/yourloginname/my notepad installer/project configuration/my notepad Installer. MSI. The default "project configuration" is "debug ".
In

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.