WinForm Packaging Deployment

Source: Internet
Author: User
Tags logical operators

1. Create a WinForm installation project using the VS bring-your-own packaging tool

Development environment: VS. Access

Operating system: Windows XP

Development language: C #

Step: The first step: open the development environment VS2008, new project, select Other project type, then select "Installation Project", enter the name and select the installation path;

The second step: go to the File System tab, select the Application folder, in the middle of the blank area right-click "Add File", add the project file (Exe,dll);

The third step: Add the files required for the project; There are two folders to be aware of (database and report) because database is the storage of project databases, and reports is the reporting file that is required to store the project. Rpt, so, in the application folder, you also need to build folders with the same name. and add the required files.

Effect:

Fourth step: To see the installer in the Start menu and in the desktop application, here we need to create a shortcut for the project.

Right-Select the executable file (PersonFinance.exe), create a shortcut, rename "* * Company * * Management System", drag and drop the shortcut into the ' User's 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

Fifth step: Set the prerequisites, right-Select the installation project, go to the property page, click the "Prerequisites" button to enter the Prerequisites dialog box;

Tick "Create Installer to install Prerequisites", in the Install Prerequisites list, select

1), Windows Installer 3.1 (required)

2),. NET Framework 3.5 (optional) Reference last description

3), Crystal Reports Basic for Visual Studio2008 (x86,x64) (optional) in the project, you need to tick this.

Important: Tick the "Download prerequisites from the same location as my application (D)", which means that when you tick, when you build the Setup project, the components that you check in the prerequisites list are available under the path of your installation project. (The system automatically completes, this is good, do not need you to download components)

Sixth step: Uninstall the program, because the installation package can not be installed only after the program, but also uninstall the program

First of all, under the "C:\WINDOWS\system32" path, locate Msiexec.exe add to the application folder, create a shortcut, and name "Uninstall Management system" or "Uninstall"

Second, choose the ProductCode of the installation project

Right-click the uninstall program shortcut, enter the properties, enter/x and ProductCode in the arguments option; For example:/x {6931bd71-5c5e-4da1-a861-14c7d1a78b97}

Store the uninstaller in a folder in the user's Start menu (new in step fourth)

Seventh Step: Change the Setup properties, right-Select the Setup project properties, you can set the project author and name, and other property information can be set according to the actual situation.

Eighth step: When you build the build of the installation project, some warnings appear:

"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:

The first: None of them are processed.

The second type: the first type of warning, you can write an uninstall program

Second type of warning: delete the same file

The installation project is finished.

Attention:

1. The. NET Framework framework is optional, not necessarily that you are using VS2008 development to use the. NET Framework 3.5, as long as you are not using the. NET Framework 3.5 features in your program such as (LINQ), then when you select the framework , you can choose 2.0, why? Because 2 is only 20 MB, and 3.5 is more than 200 MB.

How to change: there is a detected dependency file under the installation project, double-click the Microsoft. NET Framework inside, enter the boot condition selector card, right-select the. NET frmaework in version to select the. NET Framework framework that you want

2.vs2005 package, and automatically install SQL database one). Create a deployment project

1. On the File menu, point to Add Project, and then select New Project.
2. In the Add New Project dialog box, select Setup and Deployment projects in the Project Types pane, and then select Setup Project in the Templates pane. In the Name box, type Setup1.
3. Click OK to close the dialog box.
4. The project is added to Solution Explorer, and the File System Editor opens.
5. In the Properties window, select the ProductName property and type the information management system.

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

1. In the File System Editor, select Application Folder. On the Action menu, point to Add, and then select Project Output.
2. In the Add Project Output Group dialog box, select your program in the Project drop-down list.
3. Click OK to close the dialog box.
4. Select the primary output and content files groups from the list, and then click OK.

III). Creating the Installer Class

1. On the File menu, point to New, and then select Project.

2. In the New Project dialog box, select Visual Basic project in the Project Types pane, and then select Class Library in the Templates pane. In the Name box, type Installdb.
3. Click Open to close the dialog box.
4. From the Project menu, select Add New Item.
5. In the Add New Item dialog box, select Setup class. In the Name box, type Installdb.
6. Click OK to close the dialog box.
7. The detailed code is attached.

IV). Create a Custom Installation dialog box

1. Select the "Setup1" project in Solution Explorer. On the View menu, point to Editor, and then select User interface.
2. In the User Interface Editor, select the startup node under install. On the Action menu, choose Add Dialog box.
3. In the Add Dialog dialog box, select the License Agreement dialog box, and then click OK to close the dialog box.
4. In the Add Dialog dialog box, select the text Box (A) dialog box, and then click OK to close the dialog box.
5. On the Action menu, select Move Up. Repeat this step until the text box (A) dialog box is on top of the installation folder node.
6. In the Properties window, select the BannerText property and type: Install the database.
7. Select the BodyText property and type: Setup will install the database on the target machine
8. Select the Edit1Label property and type: Database name:
9. Select the Edit1Property property and type CUSTOMTEXTA1
10. Select the Edit1Value property and type: Dbservers
11. Select the Edit2label property and type: Server name:
12. Select the Edit2property property and type CUSTOMTEXTA2
13. Select the Edit2value property and type: (local)
14. Select the Edit3label attribute and type: User name:
15. Select the Edit3value property and type: SA
16. Select the Edit3property property and type CUSTOMTEXTA3
17. Select the Edit4label property and type: password:
18. Select the Edit4property property and type CUSTOMTEXTA4
19. Select the Edit2Visible, Edit3Visible, and Edit4Visible properties and set them to True

Five). Create a custom action

1. Select the "Setup1" project in Solution Explorer. On the View menu, point to Editor, and then select Custom Action.
2. In the Custom Action Editor, select the installation node. On the Action menu, choose Add Custom Action.
3. In the Select Items in Project dialog box, double-click Application Folders.
4. Select the primary output from INSTALLDB (active) Item, and then click OK to close the dialog box.
5. In the Properties window, select the CustomActionData property and type "/dbname=[customtexta1"/server=[customtexta2]/user=[customtexta3]/pw D=[CUSTOMTEXTA4]/targetdir= "[targetdir]\" ".

Attached:/targetdir= "[targetdir]\" is the target path after installation, in order to obtain the installed path in the Installdb class, we set this parameter.

VI). Add Files

1. Add the SQL Server backup file DB.dat to the "Setup1" project (in Enterprise Manager, right-click Database--All work---backup database, back up as 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, set the Lisencefile property to Lisencefile.rtf file
4. Typically, dependencies are automatically added to "Detected dependencies", and if not, we will manually add them to step 5)
CRYSTAL_MANAGED2003.MSM (if there is a crystal report)
DOTNETFXREDIST_X86.MSM (. NET must be required)
... (If you have references to other DLLs)
5. If you are using a crystal report, manually add the files you want to include: item-to-Add (add your program files) (including dotNetFramework and MDAC27), located at: C:\Program Files\Common Files \merge modules\, * for the necessary
The specific functions are as follows:
(Managed component MSM handles distribution of all managed components, including Windows Forms Viewer, Web Forms Viewer, and all Crystal decisions namespaces)
* CRYSTAL_MANAGED2003.MSM
Crystal_managed2003_chs.msm
(For all other files required to make the report run, the database access MSM handles its distribution.) These include database, export, and chart drivers. )
* CRYSTAL_DATABASE_ACCESS2003.MSM
Crystal_database_access2003_chs.msm
(KeyCode MSM handles the installation of Crystal decisions key numbers, note that the merge module is added, otherwise there is no "mergemouduleproperties" attribute)
* CRYSTAL_REGWIZ2003.MSM
(If the report file uses the ADO DataSet DataSet object, then the vc_user_crt71_rtl_x86_---. MSM and vc_user_stl71_rtl_x86_---. MSM modules must also package Included in the installation project. And the "module Retargetable Folder" entry for the file installation properties of these two modules must be modified to be a system directory)
Vc_user_crt71_rtl_x86_---. MSM
Vc_user_stl71_rtl_x86_---. MSM
(Many people often have query errors, you may add this)
5. Open the solution-right click on the properties of CRYSTAL_REGWIZ2003.MSM, "License key" in "Mergemouduleproperties" Fill in: Aap5gks0000gde100ds (this is the password for the registration number you used to generate the Crystal Report!) )

VII). Add Uninstall function when Packing: method one:

1. Add file msiexec.exe to package items (usually found under c:\windows\system32\)
2. In the file system, select the application file folder, right-click on Msiexec.exe, select Create Shortcut, rename shortcut to "Uninstall".
3. Change the arguments of this shortcut to "/x {Product ID}", the value of the product ID is the ProductCode value of the package purpose.
Method Two: (recommended)
1. To install the package, make a note of ProductCode (choose Solution Explorer root directory such as Setup1, then view the property label, not the right-click property), use the following
2. Create a new console program with vs.net 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 own ProductCode
End If
Myprocess.close ()
End Sub
End Module
3. Add the exe file of the console program Bin directory to the wrapper file

Method Two:

C # 's WinForm, the database is SQL2K,
The application includes the following files:
1.exe,1.dll,1.jpg,1.xml,donetsetup.exe and Database file 1.mdf,1.ldf (or database installation file 1.sql).
Packaging Requirements:
(1) Automatically detect whether the installation of Donet environment, if not installed, prompts for automatic installation.
(2) Install the database automatically (additional MDF or run 1.sql).
(3) You can customize some installation images or prompts on the installation screen.

Installation project:

Six subkeys: File system, registry, file type, user interface, custom action, launch condition.
The file system, registry, user interface, and custom actions are often used in the packaging process.

File system:

Output project files (four types: folder, project output, files, and assemblies) to the application folder, the user's program menu, the user's desktop, or create a shortcut (typically placed on the desktop or Program menu) The file System Editor represents the file system on the target computer, Use this tool to specify the location of the application file installation. In most cases, you want to place the application file in application folder or in a subfolder created under Application folder. After installation on the target computer, files from the application folder will be located in the Program Files/manufacturer/productname folder, where manufacturer is the installation of Visual Studio While ProductName is the name used for the deployment project. You can override both settings in the Properties window of the Setup project.

Registration form:

You can insert a key into the registry to create a registry key while the application is installed.
User interface: The system automatically provides a set of default dialog boxes that are displayed during installation. Depending on the type of project you are building, the set of dialog boxes provided is different. Using the user Interface Editor, you can reorder or delete dialog boxes. The dialog tree that is displayed in the editor contains two parts: Installation and administrator installation. The installation section includes the dialog box that is displayed when the end user runs Setup, and the Administrator installation section contains the dialog boxes that are displayed when the system administrator uploads the installer to a network location. If you want to build an installation that does not have a user interface, simply delete all the dialog boxes in the Installation section on the dialog tree. Alternatively, you can add a dialog box to the Setup project from a set of available templates.
Launch condition: Use the Launch Condition editor to define the conditions that must be met to successfully run the installation. For example, you can check for a specific version of the operating system. If the user tries to install on a system that does not meet the criteria, the installation is aborted. You can also configure launch conditions to search for a specific file, registry key, or component on the target computer. When you start the installation, Windows Installer performs search and condition evaluations and executes in the order shown in the Launch Conditions Editor.

Custom Actions:

The custom action provides a mechanism for performing tasks at the end of the installation. For example, you might want to configure the database before you install the application, and you can use a custom action to complete the creation of the database. Custom actions are built as separate. dll or. exe files and then added to the project using the Custom Action Editor, which is related to the different installation phases. The Custom Action Editor includes several separate folders for placing binaries that perform Install, Commit, Rollback, or Uninstall tasks.
InstallerClass Property: If you add a custom action that inherits from the installer class (note which folder you want to overload and which corresponding method is to be overloaded), the property is set to true, otherwise the property is set to False (note: the entry for the. dll file to be specified when false) --entrypoint property).

Unloading:

You can provide an uninstall shortcut in the installation application, with the help of the system-provided uninstaller Msiexec.exe (in the C:/windows/system32 directory), and assigns the ProductCode property value of the installer project to the Arguments property of the shortcut (note: Add/x before the property value)

Installation program class:

Under the System.Configuration.Install namespace
The installer class has four methods that can be overloaded, namely Install,commit,rollback,uninstall.
Corresponds to four folders in a custom action: Install, submit, rollback, uninstall.

Database installation: 1, additional database
2. Execute the SQL statement that created the database
3. database file restore for full backup
You can deploy the files that can generate the database (detached database files, SQL script files, or full backup files) to the application folder, and then add the generated database code in the overloaded Install method (note: The code that generates the database should be called after the base class's Install method).
Unload the database: first delete the database, then call the base class's Uninstall method to delete the files in the application folder (the order can not be messy). Several special points: 1, the Alawayscreate attribute in the file system: This property can be specified as false, Then the condition property is empty when the Alawayscreate property is true (the Transitive property must be true to calculate the value of the Condition property). The Condition property can be used to add conditional logic to the Setup program, 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 when the specified item is not found. It can be a Windows Installer condition or property that contains a value, a Name property in a file, a registry, or a component search, or a combination of the preceding statements using logical operators.
2, create shortcuts (created in the program, can have as additional tasks, according to the user's choice, there is a choice to create):
Add Reference: COM tab and select Windows Script Host Object Model
Create object: Create an instance object of WshShell, and then use the object's CreateShortcut method to create an instance object of the Iwshshortcut interface, passed to CreateShortcut The parameter of the method is the full path to the shortcut that will be created, including the name of the shortcut.
Set properties: TargetPath, WorkingDirectory, WindowStyle, Description, iconlocation
Generate shortcut: Call the Iwshshortcut.save method to generate the shortcut file.

WinForm Packaging Deployment

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.