(i), installation program
Previously used vs made the installation program, now the steps to write, help everyone must top OH
Step One: Build a project
1. Open vs, New project and other project types install and deploy (this subkey has the installation project and the Web installation project, etc., the installation project is the normal desktop program installation, the Web installation is the installation of the Web site, usually installed under IIS, the Normal desktop program installed as an example), Create a new Installation project, named Setuptest.
2. After you create a new project, you can see the subkey in Solution Explorer: File System Editor, Registry Editor, file Type Editor, user Interface Editor, Custom Action Editor, launch Condition editor. Here are some examples of how to use each place.
3. The simplest one installer: Click "File Type Editor", find "Application Folder", add file, select the program file you want to package (for example, my program has Run.exe and lib.dll composition), OK. Click Build on the Project "Setuptest" and a simple installation package is ready. After the build, click Install, if there is no error, you can now see the effect of your installation package.
4. How do I customize the code? In the production process, these simple functions do not meet your requirements, then write your own code to complete it.
Add-New project--class library named library, under Project library, delete Class1.cs, add new project--- Setup class (named InstallerTest.cs), open InstallerTest.cs, you will find this class installertest inherit from installer, inside a constructor. Well, now that the installer can't complete the function, you can write code in this class to implement it yourself.
Example: Add this to the constructor. Beforeinstall + = new Installeventhandler (Installertest_beforeinstall), implementing Method Installertest_beforeinstall (object sender, Installeventargs e), you can complete the program before the installation of things to do, installer mainly to use the event is just this: Beforeinstall,afterinstall,afterrollback, Afteruninstall,beforerollback,beforeuninstall, obviously, it doesn't have to be explained.
Install File instance code (batch processing after installation)/////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////
Public Installertest ()
{
InitializeComponent ();
This. Beforeinstall + = new Installeventhandler (Installertest_beforeinstall);
This. Afterinstall+=new Installeventhandler (Installertest_afterinstall);
}
private void Installertest_afterinstall (object sender, Installeventargs e)
{
throw new ApplicationException ("suc OK");
String path = this. context.parameters["TARGETDIR"];
string command = path + "\\a.bat";
Process P = new process ();
p.StartInfo.FileName = "cmd.exe";
P.startinfo = new System.Diagnostics.ProcessStartInfo (command);
P.startinfo.useshellexecute = false;
P.startinfo.redirectstandardinput = true;
P.startinfo.redirectstandardoutput = true;
P.startinfo.createnowindow = true;
P.start ();
P.standardinput.writeline ("Exit");
P.close ();
}
END////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
5. Completed the 4 Installertest_beforeinstall method, is not to be installed before the implementation of the code in Installertest_beforeinstall, the answer is no. Also use the Custom Action Editor. Project setuptest-> Add project Output---Select the library after you determine, you will find that under the project Setuptest there is a "main output from the library (activity)" word. Okay, here we go. At custom actions, you can see four subkeys: Install, Commit, rollback, uninstall. On the installation, right-click Add Custom Action, select "Primary output from library (active)". Then, after the rebuild, the Installertest_beforeinstall code is executed before the installation. (Of course, if you want to do something before and after the uninstallation, you must also add the custom action in the "uninstall", or even listen to the event Afteruninstall, will not be executed, the complete strategy is to install, commit, rollback, uninstall the main output from the library (activity) Added to it is not afraid, hehe)
6. How do I get the user selected installation path? In the implementation of the code, the user selected installation path is used in most cases, how to get his value? In the custom action, install, "main output from the library (activity)" Right-click on the property, in CustomActionData fill in the/targetdir= "[targetdir]/", Then in the class installertest with this sentence this.context.parameters["TARGETDIR" will be able to obtain the installation of the directory.
7. How do I get more information when the user enters the installation? Users in the installation, there may be required many other information, such as I have done before a setup file contains the installation database, installation of the user will fill in the database password, user name and other information. The implementation is as follows: User interface, install, start, right-click Add dialog box, select text Box (a), and you can see that the text box (a) has many properties, such as: Edit1label,edit1property,edit1value, Edit1visible and so on, Edit1Label is this input box to enter the content of the prompt, Edit1Value is the input content.
For example: Fill in the Edit1Label content "Please enter database user name:", fill in the Edit1Property content Dbuser,edit1visible Select True, in addition to the CustomActionData mentioned in 6, add up/ Dbuser= "[Dbuser]", and then in installertest with this sentence this.context.parameters["Dbuser"] can or have users fill in the installation of the user name (Other radio box, check box, The button box is almost a method of getting a value, no longer burdensome. In short, after adding some dialog boxes, put the properties well and add a/parm= "[attribute value]" to customactiondata in order to get the change in the code.
8. Other: Create a shortcut, you may be in the program to create multiple shortcuts, here is a way to write code to create a quick way (the meaning of the various options are not said, some of the options are not needed, the reader can test their own choice to use)
Add Reference: COM name is called Windows Script Host Object Model
Using Iwshruntimelibrary;
String DK = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Desktop);//Get Desktop Folder
Iwshruntimelibrary.wshshell shell = new Iwshruntimelibrary.wshshellclass ();
Iwshruntimelibrary.iwshshortcut shortcut = (iwshruntimelibrary.iwshshortcut) shell. CreateShortcut (@dk + "///shortcut to Data Center Sitedatacenter.lnk");
Shortcut = (iwshruntimelibrary.iwshshortcut) shell. CreateShortcut (@dk + "//Internet Public Internet service location information security management system. LNK");
Shortcut. TargetPath = @ "%homedrive%/program files/internet explorer/iexplore. EXE ";
Shortcut. Arguments = "http://localhost/web/Main.html";//Parameters
Shortcut. Description = "Mars Network Security Limited Liability company";
Shortcut. WorkingDirectory = pathweb;//The folder where the program is located, right-click on the shortcut icon to see this property
Shortcut. IconLocation = "notepad.exe, 0";//Icon
Shortcut. Hotkey = "ctrl+shift+n";//Hotkey
Shortcut. WindowStyle = 1;
Shortcut. Save ();
9. How do I run a program automatically after the installation is complete (e.g. Run.exe)?
Write this code in Afterinstall:
System.Diagnostics.ProcessStartInfo psiconfig = new System.Diagnostics.ProcessStartInfo (path +/HTTP// Www.cnblogs.com/lmjob/admin/file://run.exe ");//path is the installed directory
System.Diagnostics.Process pconfig = System.Diagnostics.Process.Start (psiconfig);
(b) Unloading (The following is a turn, spectators themselves to extract useful information)
1. Create a new C # Windows from project to complete the work of the project
2. Menu-"File-" Add Project-"New Item-" Install Deployment Project-"Installation Wizard
Select the main output of the project above.
In the property bar of the installation project, "XXX Deployment project Properties" will be displayed, "Browse" to your ICO icon after the first AddRemoveProgramsIcon property, and then enter the author's name in the following author, which is your name, The other localization is the language attribute, and the Manufacturer,productname property will be part of the folder path that the user defaults to when installing, setting the title to your application header name.
3. Right-click on "Setup Project" and select File System view
In the Application folder, add a file, if it is installed under WIN98, select the Msiexec.exe file under the WIN98 operating system directory (typically in the C:/windows/system directory); if other, such as the Win2K series, Please select the Msiexec.exe file under the operating system directory (typically in the/winnt/system32 directory).
4. In the file system view of the "User Program menu", add a directory, named as the name of the project,
And, in this directory, add a shortcut that points to the main output of the project,
Add a shortcut to the file Msiexec.exe, named: "Uninstall",
5. In the solution, select the Setup project, then open the Properties view and open the Properties panel for the installation project, with one item:
ProductCode {5284694c-24c1-4fcf-a705-d4b9a0081274}
Copy the following {5284694c-24c1-4fcf-a705-d4b9a0081274}.
6. In the "Unload" shortcut properties, there is a property bar called arguments, in the property bar first fill in "/X" followed by a space, and then "paste", the ProductCode property value copy to this.
7, then "Generate"-"Generate XXXX" (XXXX for your project name) in the top menu bar of vs.net
Add: Use of merge module projects
If in a large-scale installation program, modules fly into Module 1, Module 2, and so on, each time the module n files added to recompile is very troublesome, which is available "merge module project (MergeModule)".
1. Create a new merge module project with the name MergeModule1, add the required files, and when generated, you will see MERGEMODULE1.MSM
2. In this large installer, add "merge module" to add MERGEMODULE1.MSM
3. Build, install, you will find MergeModule1 content is also installed in the installation directory
from:http://blog.csdn.net/swarb/article/details/7074647
"Go" C # WinForm Setup package (custom action)