Create a Windows installation item - PART 1 (on)

zhaozj2021-02-11  146

Create a Windows installation item - PART 1 (on)

http://www.devarticles.com/Art/1/450/

Author: Wrox Team published: 2003.3.6 translation: Zou Jianqiang

Translation: The translator has tested the operation steps of the original author. Some operations are not the same as the Chinese version, perhaps the difference in the version, the translator's version is the Chinese version of the vs.NET 2003. So if there is a difference, I will give the operation guidance for my version and retain the English translation. In addition, the Chinese translation of the menu and dialog box in the original article is in accordance with the VS.NET 2003 Chinese version actually display name transfication, please indicate the source due to the original author's Wrox team still does not have a Part 2 section, so the current translation is only available to everyone. PART 1 content, after the PART 2 is there, I will translate to everyone. Very strange why Wrox did not have PART 2 for so long.

summary

There is already too many discussion on "zero-touch" or Xcopy deployment. Therefore, if you develop an application wants to distribute multiple users (or packages), you need a convenient and automatic way. Visual Studio .NET's MSI (Windows Installer Projects) provides local support. These items (MSI) are used to make an installer, the installer can selectively copy files, establish shortcuts and registry settings, and receive users' input. In this article, we think about how to construct a simple installer for .NET desktop applications.

Windows Installer Service Introduction

MSI technology is not very clear for .NET applications. In fact, it contains all versions of the Windows operating system (Windows 2000 / ME / XP), for Windows 98 and Windows NT 4, which can be used as a separately downloaded package. Its features include:

Support system maintenance installation data database. Windows users use this database to uninstall software without damaging other applications.

Support self-fixing, this feature allows you to modify and delete files, which automatically extracts recovery from the Windows installer. If there is a curious user who has made some unique operations, it will allow recovery of your application. What you have to do is to right-click your original installation file and select Repair according to the context menu.

Support switching installation. If there is a user who has failed installation or half installation, any changes caused by the installation will be revoked, only the status of the same is true before the installation is left.

The Windows installation file is always in the .msi extension, which is registered on the Windows Installer service (generally c: /winnt/system32/msiexec.exe). Although they seem to have no different installations, the MSI file does not contain a setup device (.exe file) that is traditional isolated. Instead, they rely on the construction of the WINDOWS operating system installation service. This service provides several predefined dialogs and limited number of pre-adjusted configurations.

Note that the Windows installation project is not true .NET project is important. They are not encoded in .NET language, of course, the CLR will not be used. Therefore, Visual Studio .NET can help you easily build a .NET program-based Windows installation project, automatic taking assembly, and slave items. Don't write the installation script at all, use the option you can use with the options provided by the Visual Studio .NET Designer and the Properties window.

Project example

We will establish an installation example of a .NET project in this article, as shown below: This routine allows the user to select font from the drop-down list. This font will pass a Paint event handle on the Form surface. The FORM code is as follows (the code has been removed from the Windows Designer area):

public class main: System.Windows.Forms.Form {private void main_Load (object sender, EventArgs e) {InstalledFontCollection fonts = new InstalledFontCollection (); foreach (FontFamily family in fonts.Families) {lstFonts.Items.Add (family.Name }}

Private void main_paint (Object sender, painteventargs e) {if (Lstfonts.Text! = ") {Try {E.Text, New Font (Lstfonts.Text, 50), Brushes.black, 10, 50); statusbar.panels [0] .text = "";} catch (exception err) {status bar.panels [0] .text = err.Message;}}}

Private void Lstfonts_Selected Indexchanged (Object Sender, Eventargs E) {if (Lstfonts.Text! = ") this.invalidate ();}}

Create a Windows installation item

You can create a Windows installation item using the above example, or add it to an existing solution. The rear solution is usually better because it guarantees that the project source file and the installer are conveniently linked together in the same solution. This is also a way to use other font browsing programs.

At the beginning, open a project that requires the installer. Right-click on the Solution in the Solution Explorer window and select Add New Project. Select Setup Project and Deployment Projects. (Translator Note: The above operation cannot be consistent with the Chinese version. The steps used in the Chinese version are written together for reference: After opening an existing item, open "file" / "add item" / " New project "/" Installation and Deployment Project ")

After you type the project name, click "OK".

At the same time, you need to configure the generation option of your solution, otherwise you run this program from the IDE, and the source project and installation item will be generated. A typical installer takes a few minutes to generate, which is definitely a waste of time and is bored.

In order to change this, you can do the following: Right-click on the installation item you just created in the Solution Explorer, then select Properties. The following window appears. Select "Configure Properties" and clear this installation item "Generate" option (VS.NET 2003 Chinese version of the operation) After the following window, select Configuration Manager, clear "generation" in the configuration manager. Option check box). Now the installation file will not be created automatically. When you are created manually, just choose the "Generate" option above.

Installation designer

When you create a installation item, Visual Studio .NET provides several different designers, each of which is only one aspect of the installer. In order to see all the designers that can be used, right-click the installation project name you established in the Solution Explorer, then select "View".

The file system designer allows replication files to the target computer. You can use a predefined folder, or choose a few public folders (Translator Note: Program Files, Desktop, Program Menu, etc.). The Registry Designer allows you to add new keys and key values ​​to the target computer registry. File Type Designer allows you to register a file extension for your application (by double-clicking on such a file to activate your program). These settings can also be carried out by the registry designer, but there will be many operations involved. The User Interface Designer allows a default user installation interface (which is automatically supplied), or you can add a custom dialog. Custom Operation Designer allows you to link additional programs, starting it to perform additional configuration operations after the installer ends. The Start Condition Designer allows you to describe the conditions that must be met in order to install and run (the translator Note: Programs based on .NET environment support can detect whether the target computer system environment is satisfied by this project).

You can also set more basic options, such as: authors, manufacturers, manufacturers links, headings, product names, and version numbers from the project properties window. Most of these description information is used in the Installation Wizard or another window dialog, like supporting the information window (it can start from the fill / delete program window). You can also set up an icon that represents your program in the list of current installed programs (AddRemoveProgramsicon).

Add files, project output and shortcuts

The first step in creating an installer is to specify the file you want to copy to the target computer and do it through the file system designer. You can specify that adding these files to a folder below a system confirmation, such as: System folder, Fonts folder, GAC (Global assembly cache) folder, or even the user's My Documents folder. You can also add a file to a hardcoded path (using the custom folder option), or the user is a directory for the application (Application folder). The following shows all the supported folder options: File System Designer Window is divided into two panels: the left is a folder list, and the right is the currently selected folder list. You can right-click the folder list to select Add a special folder to add a new folder.

转载请注明原文地址:https://www.9cbs.com/read-5926.html

New Post(0)