Winform packaging and deployment

Source: Internet
Author: User
Document directory
  • File System:
  • Registry:
  • Custom operations:
  • Uninstall:
  • Installer class:
  • Several special points:

1. Use the package tool provided by Vs to create a winform installation project.

Development Environment: VS 2008 access

Operating System: Windows XP

Development language: C #

Step 1: Open the development environment vs2008, create a project, select another project type, select "Installation Project", enter the name and select the installation path;

 

Step 2: Go to the file system tab, select the application folder, right-click the blank area in the middle and select "add file" to add the project file (exe, DLL );

 

Step 3: add the files required for the project. Here there are two folders (database and report), because database is used to store the project database, and report is used to store the report files required by the project. rpt. Therefore, you must create a folder with the same name in the application folder and add the required files.

Effect:

 

Step 4: Create a shortcut for the project to view the installer in the Start Program menu and in the desktop application.

Right-click the executable file (personfinance.exe), create a shortcut, rename "** company ** Management System", and drag the shortcut to the 'user "program" menu. Repeat this step to add the new shortcut to the "user desktop" folder.

It is best to create a folder in the user menu to store the installer

 

Step 5: Set system prerequisites, right-click the installation project, go to the properties page, and click "system prerequisites" to go to the system prerequisites dialog box;

Select "create installer for installing required system components", and in the list of required system components to be installed, select

1) Windows Installer 3.1 (required)

2). Net Framework 3.5 (optional) refer to the final description

3) in the crystal report basic for visual studio2008 (x86, x64) (optional) project, you must select this option when using the crystal report.

Important: Check "Download essential system components (d) from the same location as my application", which means that when you select this option to generate the installation project, under the path of your installation project, you will find the components you have selected in the list of required components. (The system automatically completes. This is not bad because you do not need to download the components yourself)

 

Step 6: uninstall the program, because after the installation package is completed, you cannot only install the program, but also uninstall the program.

First, under "C: \ WINDOWS \ System32", find msiexec.exe to add it to the application folder, create a shortcut, and name it "Uninstall management system" or "Uninstall"

Next, select the productcode of the installation project.

Right-click the shortcut to uninstall the program and choose properties. In the arguments option, enter/X and productcode. For example,/X {6931bd71-5c5e-4da1-a861-14c7d1a78b97}

Store the uninstallation program to the user's Start Menu folder (New in step 4)

Step 7: change the properties of the installer, right-click the properties of the installation project, and you can set the author and name of the project. Other properties can be set according to the actual situation.

Step 8: generate an installation project and generate it with the following warning:

Msiexec.exe should be excluded because its source file "C: \ windows \ system32 \ msiexec.exe" is protected by "Windows system files ";

Two or more objects have the same target location ("[targetdir] \ model. dll ")
Solution:

First: Do not process

Second: the first type of warning. You can compile the uninstall program.

Second warning: Delete the same file

The installation project has been created.

 

Note:

1 ,. net Framework framework is optional. It is not necessarily required for vs2008 development. net Framework 3.5, as long as you do not use it in the program. net Framework 3.5 features such as (LINQ), you can select 2.0 when you select the framework. Why? Because 2.0 only has more than 20 MB, and 3.5 has more than 200 MB.

Change Method: There is a detected dependency file under the installation project, double-click Microsoft. net Framework, enter the startup Condition Selection card, right-click to select. net frmaework select the one you need in version. net Framework framework

 

2. Package vs2005 and automatically Install SQL database 1). Create a deployment project

1. Point to "add project" on the "file" menu and select "new project ".
2. 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 setup1.
3. Click OK to close the dialog box.
4. The project is added to Solution Explorer and opened in the file system editor.
5. In the "properties" window, select productname properties and type the information management system.

2). Add the output of the main program project to the deployment project.

1. In the file system Editor, select Application folder ". On the "operations" menu, point to "add" and select "project output ".
2. In the "add project output group" dialog box, select "your program" from the "project" drop-down list ".
3. Click OK to close the dialog box.
4. Select the "main output" and "Content File" groups from the list, and click "OK ".

3). Create the installer class

1. Point to "new" on the "file" menu and select "project ".

2. In the "new project" dialog box, select "Visual Basic Project" in the "project type" pane and select "class library" in the "template" pane ". In the "name" box, type installdb.
3. Click Open to close the dialog box.
4. Select "Add new project" from the "project" menu ".
5. In the "Add new project" dialog box, select "Installer class ". In the "name" box, type installdb.
6. Click OK to close the dialog box.
7. The detailed code is attached.

4). Create a custom installation dialog box

1. Select the "setup1" project in Solution Explorer. On the "View" menu, point to "Editor" and select "User Interface ".
2. In the User Interface Editor, select the "Start" node under "installation. On the "operations" menu, select "add dialog box ".
3. In the "add dialog box", select the "License Agreement" dialog box and click "OK" to close the dialog box.
4. In the Add dialog box, select the text box (A) and click OK to close the dialog box.
5. On the "operations" menu, select "Move Up ". Repeat this step until the "text box (a)" dialog box is located on the "Install Folder" node.
6. In the "properties" window, select the bannertext attribute and type: Install database.
7. Select the bodytext attribute and type: the installer will install the database on the target machine.
8. Select the edit1label attribute and type: Database Name:
9. Select the edit1property property and type customtexta1
10. Select the edit1value attribute and type dbservers.
11. Select the edit2label attribute and type: Server Name:
12. Select the edit2property property and type customtexta2
13. Select the edit2value attribute and type: (local)
14. Select the edit3label attribute and type: User Name:
15. Select the edit3value attribute and type: SA
16. Select the edit3property property and type customtexta3
17. Select the edit4label attribute and type: password:
18. Select the edit4property property and type customtexta4
19. Select the edit2visible, edit3visible, and edit4visible attributes and set them to true.

5). Create a custom operation

1. Select the "setup1" project in Solution Explorer. On the "View" menu, point to "Editor" and select "Custom operations ".
2. Select the "Install" node in the Custom operation editor. On the "operations" menu, select "add custom operation ".
3. In the "select project items" dialog box, double-click "application folder ".
4. Select "primary output from installdb (activity)" and click "OK" to close the dialog box.
5. in the "properties" window, select the customactiondata attribute and type "/dbname = [customtexta1]/Server = [customtexta2]/user = [customtexta3]/Pwd = [customtexta4]/targetdir =" [targetdir] \ "".

Appendix:/targetdir = "[targetdir] \" is the target path after installation. To obtain the path after installation in the installdb class, we set this parameter.

6). Add files

1. back up SQL server to a file dB. add dat to the "setup1" project (right-click the database in the Enterprise Manager> all jobs> back up the database and back up it into a file named dB. dat)
2. Add the Installation File lisencefile. rtf to the "setup1" project.
3. In the User Interface Editor, select the license agreement and set the lisencefile attribute to the lisencefile. rtf file.
4. Generally, dependencies are automatically added to "detected dependencies". If not, manually add them to Step 5)
Crystal_managed2003.msm (if there is a crystal Report)
Dotnetfxredist_x86.msm (. NET must be required)
... (If any other DLL is referenced)
5. if a crystal report is used, manually add the file to be included: Project --> Add --> Merge Module (add your program file) (including dotnetframework and mdac27) at: C: \ Program Files \ common files \ merge modules \, * is required
The specific functions are as follows:
(Managed component MSM processes distribution of all managed components, including windows form viewer, web form viewer, and all crystal decisions namespaces)
* Crystal_managed2003.msm
Crystal_managed2003_chs.msm
(For all other files required for running the report, the database accesses the MSM to process the distribution. These include database, export, and chart drivers .)
* Crystal_database_access2003.msm
Crystal_database_access2003_chs.msm
(Keycode MSM processes the installation of the crystal decisions key number. Note that the merging module is added; otherwise, the "mergemouduleproperties" attribute is not available)
* Crystal_regwiz2003.msm
(If the report file uses the dataset DataSet object of ADO. net, the vc_user_crt71_rtl_x86 _ ---. MSM and vc_user_stl71_rtl_x86 _ ---. MSM modules must also be included in the installation project. In addition, the "module retargetable folder" item of the File Installation attribute of the two modules must be changed to the system directory)
Vc_user_crt71_rtl_x86 _ ---. MSM
Vc_user_stl71_rtl_x86 _ ---. MSM
(Many people often encounter query errors. You may add this)
5. open solution --> right-click the attribute of crystal_regwiz2003.msm, and fill in the "license key" in "mergemouduleproperties": aap5gks1_gde100ds (this is the registration code used to generate the crystal report !)

7). Add the uninstall function during packaging: Method 1:

1. Upload the msiexec.exe file to the package. (This file can be found in c: \ windows \ system32)
2. Upload the program file in the file system, press "right" on "msiexec.exe", select "Uninstall" to create a shortcut, and rename the shortcut to "Uninstall ".
3. Change the arguments of this shortcut to "/X {product ID}", and the value of product ID is the productcode validation value of the packaging destination.
Method 2: (recommended)
1. Complete the installation package, and write down the productcode (select the solution Resource Manager root directory such as setup1, and then view the property tag, not the right-click attribute ).
2.use vs.netto create a new console program uninst.exe File
'Power by: landlordh
'For 2000, XP, 2003
Module uninstall
Sub main ()
Dim myprocess as process = New Process
If system. environment. osversion. tostring. indexof ("nt 5") then
Myprocess. Start ("msiexec", "/X {2b65d4a9-c146-4808-ab4b-321fb0779559}") "changed to your own productcode
End if
Myprocess. Close ()
End sub
End Module
3. Add the EXE file in the bin directory of the console program to the package file.

Method 2:

C # C/S winform, the database is sql2k,
Applications include the following files:
1.exe,1.dll,1.jpg, 1.xml,donetsetup.exe and database files 1.mdf, 1.ldf( or Database Installation File 1. SQL ).
Packaging requirements:
(1) check whether the donet environment is installed automatically. If the donet environment is not installed, the system prompts automatic installation.
(2) automatically install the database during installation (append MDF or run 1. SQL ).
(3) You can customize some installation pictures or prompts on the installation interface.

 

Installation Project:

Six sub-items: file system, registry, file type, user interface, custom operation, and startup condition.
The file system, registry, user interface, and custom operations are frequently used during the packaging process.

File System:

Output project files (four types: folder, project output, files, and assembly) to the application folder, user program menu, and user desktop ), you can also create a shortcut (usually in the desktop or program menu) File System editor to indicate the file system on the target computer. You can use this tool to specify the location where the application files are installed. In most cases, you want to put the application file in application folder or a subfolder created under application folder. After installation on the target computer, the files from application folder will be located in the program files/Manufacturer/productname folder, where manufacturer is the company name used to install Visual Studio, productname is the name of the deployment project. You can override these two settings in the Properties window of the installation project.

Registry:

You can insert a key to the Registry to create a registry key while installing the application.
User Interface: the system automatically provides a set of default dialog boxes displayed during installation. The provided dialog box varies depending on the type of the project being built. You can use the user interface editor to re-sort or delete the dialog box. The dialog tree displayed in the Editor contains two parts: Installation and administrator installation. The installation part includes the dialog box displayed when the end user runs the installer, and the Administrator installation part includes the dialog box displayed when the system administrator uploads the installer to a network location. To create an installation without a user interface, you only need to delete all the dialogs in the installation section in the dialog box tree. Alternatively, you can add the dialog box to the installation project from a set of available templates.
Conditions: Use the Conditions Editor to define the conditions required for successful installation. For example, you can check the operating system of a specific version. If you try to install it on a system that does not meet the requirements, the installation will stop. You can also configure startup conditions to search for a specific file, registry entry, or component on the target computer. When you start the installation, the Windows Installer performs a search and condition evaluation, and runs the evaluation in the order shown in the startup condition editor.

Custom operations:

Custom operations provide a mechanism to execute tasks at the end of installation. For example, you may want to configure the database before installing the application. In this case, you can use custom operations to create a database. Build a custom operation as a separate. dll or. EXE file and add it to the project using the custom operation editor. These operations are related to different installation phases. The custom operation Editor contains several separate folders for storing binary files that execute the install, commit, rollback, or uninstall tasks.
Installerclass attribute: If the added custom operation inherits the self-installer class (pay attention to which folder the corresponding method will be reloaded), this attribute is set to true, otherwise, set this attribute to false. DLL file entry -- entrypoint attribute ).

Uninstall:

You can download an example in the installation application, use the system uninstall program msiexec.exe (in the C:/Windows/system32 directory), and assign the productcode attribute value of the installation project to the arguments attribute of the shortcut (Note: Add/X before the attribute value)

Installer class:

Under system. configuration. Install namespace
The installer class has four methods that can be reloaded: Install, commit, rollback, and uninstall.
It corresponds to Four folders in the Custom operation: installation, submission, rollback, and uninstallation.

 

Database Installation: 1. Additional database
2. Execute the SQL statement used to create a database
3. Restore a fully backed up database file
You can deploy files that can generate databases (separated database files, SQL script files, or full backup files) to the application folder, then add the generated database code to the overloaded install method (Note: The generated database code should be after the base class install method is called ).
Detach a database: First Delete the database, and then call the uninstall method of the base class to delete the files in the application folder (the order cannot be messy ). Special Points: 1. alawayscreate attribute in the file system: this attribute can be set to false, if the condition attribute is null, The alawayscreate attribute is true (the transitive attribute must be true to calculate the value of the condition attribute ). The condition attribute can be used to add conditional logic to the installer. For example, to install a file only for a specific operating system version. It can also be used with file search, registry search, or component search to terminate the installation process if the specified item cannot be found. It can be a Windows Installer condition or attribute, the value contained in the property attribute, the name attribute in the file, registry, or component search, or a combination of the preceding statements using logical operators.
2. Create a shortcut (you can create a shortcut in a program as an additional task and create a shortcut based on your selection ):
Add reference: COM tab and select Windows Script Host Object Model
Create object: Create a wshshell instance object, and then use the createshortcut method of the object to create the Instance Object of the iwshshortcut interface, parameters passed to the createshortcut method are the complete path of the shortcut to be created (including the name of the shortcut ).
Set attributes: targetpath, workingdirectory, windowstyle, description, and iconlocation
Generate a shortcut: Call iwshshortcut. Save to generate a shortcut file. You can paste and splice the above reference from your garden friends. Sorry!

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.