Abstract This article discusses how to use Windows Installer technology to publish .NET programs, and how to use native code to determine whether the .NET Framework is installed on the target machine; if not, the .NET Framework will be automatically installed and then the author's own .NET program will be installed.
-------------------------------------------------- ----------------------------------
Contents of this article Make your own installer to publish the .NET Framework
Summary of how to use your own native installer by the author
------------------------------------------------ ----------------------------------------
Contents of this article
1. Use VS.NET to create the installer.
2. How to deploy .NET Framework to the target machine.
3. How to use Native code to make the .NET Framework and your own installation program into a unified installation program. This program will automatically install the .NET Framework and then automatically install the author's own program if there is no .NET Framework on the target machine.
-------------------------------------------------- -------------------------------
To make your own installer in VS.NET, we can create "Setup and Deployment Projects" "Project, it is very flexible and convenient to make your own .NET program into a Windows Installer file. For example, we can easily customize the following options:
1. Whether to place a shortcut on the desktop.
2. Register your own file type that can be opened with your own program by double-clicking the file.
3. Registry processing At the following MSDN site, we can get examples of making our own installers through Setup and Deployment Projects in VS.NET:
http://msdn.microsoft.com/library/en-us/vsintro7/html/vbconDeploymentScenarios.asp
--------------------------- -------------------------------------------------- ---
Publish .NET Framework
.NET Framework 1.0 provides an exe file used to redeploy .NET: Dotnetfx.exe. It contains Common Language Runtime and other essential content when .NET programs run.
We can download the exe file from the following site:
http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/001/829/msdncompositedoc.xml
At the same time, we can also find this file on the VS.NET installation CD or DVD.
We can deploy .NET Framework to the target machine by running Dotnetfx.exe in various ways:
1. Deployed via Microsoft Systems Management Server.
2. Deployed via Active Directory.
3. Use third-party tools.
For specific information, we can refer to the following articles:
http://msdn.microsoft.com/library/en-us/dnnetdep/html/redistdeploy.asp
--------------------------- -------------------------------------------------- ---
Make your own native installation program. If we want to publish our .NET program to the target machine, and we are not sure whether the target machine has the .NET Framework installed, then we need to design a piece of unmanaged code ourselves. Determine whether the target machine has the .NET Framework installed. If not, run Dotnetfx.exe to install the .NET Framework, and then use Windows Installer to install your own program.
On the following web page of MSDN, we can get an installer implemented in unmanaged C++ and its source code:
http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/830/msdncompositedoc.xml
1. In the CSettings class, get the path to your own MSI installation file and dotnetfx.exe, as well as other your own settings by reading "settings.ini". (such as the language version of .NET Framework)
GetCaptionText(void)
GetDialogText(void)
GetErrorCaptionText(void)
GetIniName(void)
GetProductName(void)
The Parse() function is used to parse the settings.ini file.
2. In the Main.cpp file, the global function FxInstallRequired() determines whether to install .NET Framework on the target machine. FxInstallRequired() will detect the following registry key value and the version and language settings of dotnetfx.exe.
HKLMSOFTWAREMicrosoft.NETFrameworkpolicyv1.0
3. If you need to install .NET Framework, call the following command silently in the global function ExecCmd() to install dotnetfx.exe:
dotnetfx.exe /q:a /c:"install /l /q"
4. Call the following command in the ExecCmd() global function to install your own MSI file:
msiexec /i <your MSI file> REBOOT=ReallySuppress
--------------------------------------- ----------------------------------------
How to use If we use the above native code As our own installation program, we can combine our own .NET program with it through the following steps:
1. Make your own .NET program into a Windows Installer (.MSI) file.
2. Open the "settings.ini" file and set the MSI file path and file name of your own .NET program in the "Msi" key; in the "FxInstallerPath" Key, set the path to dotnetfx.exe. Specific parameter information can be obtained from the following article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetdep/html/redistdeploy.asp
3. Send "setup.exe", "settings.ini", "dotnetfx.exe" and your own MSI installation file to the target machine, and then run "setup.exe". The installation program will automatically detect whether there is one. NET Framwork, if not, dotnetfx.exe will be run first.
Through the above steps, you can successfully deploy your .NET program to a machine that does not have a .NET Framwork environment installed.
-------------------------------------------------- ----------------------------------
Summary Through the above steps, you can successfully deploy your .NET program without installation. NET Framwork environment.
-------------------------------------------------- ----------------------------------
Author Zhang Guanghui
October 22, 2002