Winform package deployment and winform deployment

Source: Internet
Author: User

Winform package deployment and winform deployment

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

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 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!

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.