2005.2.1 ou yanliang
Content
This section describes how to configure and deploy Windows applications and how to convert application code into a product.
Course Basics
Familiar with Microsoft. NET Framework
Understand basic. NET development and what is application assembly
Course Content
Configuration -- Configuration
Configuration File
System. Configuration namespace
Access the Registry
Independent Storage)
Deployment
Deployment Options
Private and shared application assembly
Updater Application Block
Configuration)
There are four different ways to configure an application:
Config files)
Generally, security is not required. It is best not to store the password in the configuration file because it exists in plaintext. If sensitive information must be stored in the configuration file, it is best to use encryption methods such as Hash to store ciphertext.
Registry)
You can store sensitive information in the registry. The Registry not only stores information, but also adds an access control list (ACL) to the registry key to ensure the access permissions of some people. You can also store infrequently changed information in the registry, such as installed version information.
Independent storage)
You can store frequently changed information, such as the layout of the toolbar, the position and size of the program window when you close the program the last time you use the software.
Database)
Flexible. We can construct any data structure.
App. config file
XML files with a certain Schema
AppSettings: Add a key/value pair
IDE copies App. config to the/debug or/releasedirectory during compilation, and changes the file name to appname.exe. config (appname is the name of our application)
The configuration options in the app.exe. config file are loaded by the framework at runtime. We can obtain the value through the key in the deletemetadata.
Custom Configuration options: Custom Configuration Sections. When we want to customize the Schema, the framework cannot automatically parse our Schema format. It can only load XML nodes for us, we can only write a class that inherits from IConfigurationSectionHandler to process our XML.
Demonstration 1
Configuration File
In the cs code, ConfigurationSettings refers to the App. in the config file, the AppSettings attribute is used to read the appSettings node in the file. It will parse all key/value pairs after all add labels in the node and convert these pairs into Hash Tables.
Custom configuration options and IConfigurationSectionHandler
<Deleetask> and <add> Configuration blocks have certain limitations.
You can create <configSections> in the header of the. config file to define your own configuration blocks.
Create a <section> for each custom block and implement the corresponding handler
Create your own section and write an XML configuration file
Create a class to implement the IConfigurationSectionHandler interface to parse XML files in custom formats
Call the Configuration. GetConfig (string SectionName) method, and the Framework will call your implemented IConfigurationSectionHandler. Create () interface.
Demonstration 2
Custom configuration Block
The DisplayBeautyTipsSection and Framework in the following section cannot be automatically parsed. Therefore, we need to use the following code to implement resolution.
Use Config
The GetConfig method of ConfigurationSettings will go to the driver Framework to read the content of the Node named DisplayBeautyTipsSection in App. config to an XML Node. Then, the Framework automatically calls the Create method of the type class corresponding to DisplayBeautyTipsSection name in the section label in the App. config file. In this example, the Create method returns the XML content as the object is. In practice, we can return a custom storage structure instead of an XML node, which makes it easier to use.
Registry
Microsoft. Win32 namespace (this space contains methods for accessing SystemAPI)
RegistryKey class: CreateSubKey (), GetSubKey (), DeleteSubKey (), GetValue (), and other methods
Four major keys:
Registry. LocalMachine
Registry. CurrentUser
Registry. ClassesRoot
Registry. CurrentConfig
You can add a Windows Access Control List (ACL) to the registry key value to Control the security of the registry key. When adding protection Permissions, its class is in System. Security. Permissions. RegistryPermission... .
Demonstration 3
Registry Access
Independent Storage)
Independent storage can be used to store user-related and frequently-changing data.
Actual storage region and Path
Support for roaming storage (domain storage)
<SystemDrive> \ Documents and Settings \ <user> \ Application Data
Non-roaming storage path (Local Storage)
<SystemDrive> \ Documents and Settings \ <user> \ Local Settings \ Application Data
All objects supporting Serializable Storage can be stored to the corresponding disk space through Isolated Storage Stream.
Code stored independently
GetStore obtains the region where the user is stored independently. IsolatedStorageFileStream creates an independently stored file in the user storage region, and then columns some user information to the file using the IFormatter string.
Demonstration 4
Code stored independently
When the application starts, it reads the user's status and restores the last application running status.
If you store data in a domain, set the attribute of isolatedstorag.pdf to Roaming, and set it to User locally. Get the specific user features by deserializing the file content.
Here, our catch does not do anything, and an exception is eaten. This is a counterexample, because when our application runs for the first time, the file Settings. isf certainly does not exist. An exception will occur when opening the file and listing it. This exception is normal at this time, so we will eat the exception here.
When the application is closed, the application program running status is stored.
In this way, when we run the application next time, the size and position of the form will be consistent with that of the last close.
However, if we copy the application and run it, the form will return to the default location. This indicates that the copied application belongs to two different application sets, for independent storage ,. NET will treat them separately.
In addition, we can find the Settings. isf file in a very deep directory on the C drive.
If we delete the file and run the program, the program will return to the default state.
Deployment Scheme
Xcopy deployment
Installation and deployment
Private and Shared application assembly
Side-by-side deployment
Xcopy deployment
Xcopy all application-Related Files:. exe assembly, referenced. dll assembly (except the. dll file in GAC), and configuration file. config
It is a good choice for simple applications and does not require much configuration work during installation.
This configuration method is not applicable if you need to register the Assembly to GAC or perform a large number of configurations for the application.
Demonstration 5
Xcopy deployment
Copy the files in the Debug or Release folder to a new directory to run the program normally.
Installation and deployment
The Setup Project template, which is located in Setup and Deployment Projects.
Package it into a. msi file
Create Installation Wizard
Custom Installation Steps
Installer class
Add an Installer class to the application assembly
It will be self-defined installation and deployment projects or installutil.exe will be called during installation
This class needs to be derived from System. Configuration. Install. Installer
Reinstall the Install method
Customized installation code
The Context. Parameters set contains the data or parameter information imported during installation.
Demonstration 6
Create Setup Project
Ms-help: // MS. MSDNQTR.2005JAN. 1033/vsintro7/html/vbtskCreatingInstallerForYourApplication.htm
By default, a Setup project is not compiled with other projects. It is skipped because the compilation speed is slow. We can set the properties of the solution to change.
After you check the Setup project, it will be compiled with other projects.
Create new shortcuts
Only by running the Setup program in the development environment will it uninstall the previously installed program by default and reinstall it. If you run the installation package directly after packaging, it will prompt whether to uninstall or Repair.
To modify the default installation path, you must modify the properties of the Setup project.
Change
Because the default DefaultLocation path attribute in the Application Folder attribute is related to this setting
To get user input during installation, you can define a variable CustomActionData:/ServerName = [EDITA1]. This is the value entered by the EDITA1 user and will be placed in the ServerName variable.
Define the installation interface in UserInterface
The EDITA1 of Edit1Property corresponds to the [EDITA1] Name in CustomActionData.
Add the Installer class and reload the Install method.
In the Installer class, you can access the "ServerName" in the Context. Parameters dictionary to obtain the value entered by the user.
The UpdateConfigFile class first obtains the current application assembly, obtains the application configuration file, reads the configuration file, and finds the position of the link string in the configuration file, replace the Server address in the connection string with the Server address entered by the user.
Private and shared application assembly
Private assembly is only visible to the executable code of the application, usually in the same directory of the executable file
Shared Assembly must have a Strong Name (Strong Name) and be installed in Global Assembly Cache (GAC ).
For shared strongly-named assembly, you can install multiple application Assembly versions to implement side-by-side deployment.
Demonstration 7
Private and shared application assembly
Copy the generated Northwind. snk to our project path, and write the path of the snk file in AssemblyInfo of the project that requires strong signature.
The assembly in the C: \ Windows \ assembly directory is the public assembly in the local computer. After compilation, we can put the compiled application assembly dll in the C: \ Windows \ assembly directory.
We can put different versions of the application assembly in this directory, so that the upgrade of the application assembly will not affect the old application. The strong signature of an application is irrelevant to Program Encryption. It only generates a key pair. GAC uses the signature to check whether the application is from the same company or location.
Updater Application Block
"Pull Mode", which automatically downloads the application assembly on the central server to run locally.
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/dnbda/html/updater. asp
Summary
. NET has multiple methods to store configuration data, including configuration files, registries, and independent storage.
Different deployment methods can be implemented based on different needs, including Xcopy deployment, installation and deployment, etc.
You can deploy the application assembly by side-by-side. In GAC, you can save multiple versions of Strongly-named assembly.
2010.10.13