Vs create an installer

Source: Internet
Author: User

(1) installProgram

I have used vs to create installation programs. Now I want to write down the steps. It is helpful for everyone.

Step 1: Create a project
1. open vs, create a project, and select another project type. Install and deploy the project (such as the installation project and web installation project under this subitem). The installation project is an ordinary desktop program installation, web installation is the installation of the website. It is usually installed under IIS. Here, the installation of Common Desktop programs is used as an example.) create a new installation project named setuptest.

2. after creating a project, you can see the Sub-item in Solution Explorer: File System Editor, Registry Editor, file type editor, User Interface Editor, custom operation editor, and start the condition editor. The following is an example of how to use it in different places.

3. The simplest Installer: click "file type editor", find "application folder", add-> file, and select the program file you want to package (for example, my program consists of run.exe and Lib. dll. Click Generate on the project "setuptest" to complete a simple installation package. After the installation is generated, click Install. If there is no error, you can now see the effect of your installation package.

4. How to customizeCode? In the production process, these simple functions cannot meet your requirements, so write your own code to complete it.

solution-> Add-> Create Project-> class library, name it library, and delete class1.cs under the project library, add-> new project-> installer class (named installertest. CS), open installertest. CS, you will find that this class installertest inherits from the installer, and there is a constructor in it. Now, you can write code in this class to implement functions that cannot be completed by the installer.
example: add this in the constructor. beforeinstall + = new installeventhandler (installertest_beforeinstall), implementation method installertest_beforeinstall (Object sender, installeventargs E), you can complete what to do before installing the program, the main events used by the installer are similar to the following: beforeinstall, afterinstall, afterrollback, afteruninstall, beforerollback, and beforeuninstall. Obviously, you don't need to explain them.

5. The installertest_beforeinstall method in Step 4 has been completed. Is it necessary to execute the code in installertest_beforeinstall before installation? The answer is no. The "Custom operation Editor" is also used ". Project setuptest-> Add-> project output-> select "library" and click "OK". You will find that the project setuptest contains an additional "active output from library. OK. Now, go to "Custom operations". You can see four sub-items: installation, submission, rollback, and uninstallation. On the installation page, right click-> Add custom operation-> select "main output from library (activity )". In this way, the installertest_beforeinstall code will be executed before the installation. (Of course, if you want to do something before and after the uninstallation, you must add custom operations in the "uninstallation" area. Otherwise, even if the event afteruninstall is monitored, it won't be executed either. The complete solution is to add the main output from the library (activity) in the installation, submission, rollback, and uninstallation processes)

6. How do I get the installation path selected by the user? When implementing the Code, the installation path selected by the user is used in most cases. How can we get the value of this path? Choose Custom operations> Installation> main output from library (activity), right-click the attribute, and enter/targetdir = "[targetdir]" "In customactiondata. then use this statement in the installertest class. context. parameters ["targetdir"] can obtain the installation directory.

7. How can I get more information input during installation? During the installation, you may also need a lot of other information. For example, a previously created installation file contains the installation database. During the installation, you must enter the Database Password, user name, and other information. The implementation is as follows: User Interface-> Installation-> Start-> right-click-> Add dialog box-> select "text box (a)", you can see that the text box (a) has many attributes, such: edit1label, edit1property, edit1value, edit1visible, etc. edit1label is the prompt of the content to be input in this input box. edit1value is the input content.
For example, fill in the edit1label content with "Enter Database User name:", fill in edit1property content with dbuser, and select "true" for edit1visible. In addition, in the customactiondata mentioned in section 6, add/dbuser = "[dbuser]" and use this statement in installertest. context. parameters ["dbuser"] can be used to obtain the user name you entered during installation (other methods such as single quotes, check boxes, and button buttons get values almost all, ). in short, after adding some dialog boxes, you must add a/parm = "[attribute value]" in customactiondata to get the modified value in the code.

8. others: create shortcuts. You may want to create multiple shortcuts in the program. Here, we will show a way to write code to create a quick method (the meaning of each option is not mentioned, some of the options are optional and can be tested and used by the reader)

Add reference: com name: Windows Script Host Object Model

Using iwshruntimelibrary;
String Dk = system. environment. getfolderpath (system. environment. specialfolder. desktop); // obtain the Desktop Folder
Iwshruntimelibrary. wshshell shell = new iwshruntimelibrary. wshshellclass ();
Iwshruntimelibrary. iwshshortcut shortcut = (iwshruntimelibrary. iwshshortcut) Shell. createshortcut (@ Dk + "sitsitsitsitsitsitedatacenter. lnk ");

Shortcut = (iwshruntimelibrary. iwshshortcut) Shell. createshortcut (@ Dk + ". lnk ");
Export cut. targetpath = @ "% homedrive %/Program Files" Internet Explorer "iexplore. EXE ";
Export cut. Arguments = "http: // localhost/web/main.html"; // Parameter
Shortcut. Description = "Mars Network Security Co., Ltd ";
Shortcut cut. workingdirectory = pathweb; // The folder where the program is located. Right-click the shortcut icon to view this attribute.
Shortcut cut. iconlocation = "notepad.exe, 0"; // icon
Shortcut cut. hotkey = "Ctrl + Shift + N"; // hotkey
Export cut. windowstyle = 1;
Shortcut cut. Save ();

9.if a program (such as run.exe) is automatically run after the installation is complete )?
Write this code in afterinstall:
System. Diagnostics. processstartinfo psiconfig = new system. Diagnostics. processstartinfo (path + "run.exe"); // path is the installation directory
System. Diagnostics. Process pconfig = system. Diagnostics. process. Start (psiconfig );

(2) uninstall (The following is a conversion, and the visitor can extract useful information by himself)

1. Create a C # windows from project to complete the project

2. Choose menu> File> Add project> new item> install and deploy project> Installation Wizard

Select the main output of the project above.

The property bar of the installation project displays "XXX deployment project properties". After the first addremoveprogramsicon property, "Browse" to your ICO icon, and then enter the author name in author, that is, your name. Other localization types are language attributes. Manufacturer and productname attributes are part of the default folder path set during installation. Set title to your application title name.

3. Right-click "installation project" and select the File System View.

Hosts file (generally in the C: "Windows" system system)))if it is another file, select the msiexec.exe file under the Operating System Directory (generally in the "winnt" system32 directory ).

4. In the "user program menu" in the file system view, add a directory named project name,

In addition, add a shortcut in this directory to point to the main output of the project,

Upload another example to the added file "msiexec.exe", named "Uninstall ",

5. In the solution, select the installation project, and then open the property view to open the property Panel of the installation project. There is one in it:

Productcode {5284694c-24c1-4fcf-a705-d4b9a0081274}

Copy the following {5284694c-24c1-4fcf-a705-d4b9a0081274.

6. in the "Unload" shortcut attribute, there is an attribute column named arguments. In the attribute column, first fill in "/X" with a space, and then "Paste ", copy the property value of productcode to this point.

7. In the top menu bar of vs. net, "generate"-"generate XXXX" (XXXX is your project name)

Supplement: Use of merging module projects

in a large installation program, module flying is divided into Module 1 and module 2. It is very troublesome to add module n files to re-compile each time, this is the "Merge Module Project (mergemodule)" available )".
1. create a new merging module project named mergemodule1. Add the required file. After the file is generated, You can see mergemodule1.msm
2. in this large installer, add the "Merge Module" and add mergemodule1.msm.
3. generate, install, and you will find that the content of mergemodule1 is also installed in the installation directory

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.