How to set the installation package to automatically install the .NET Framework environment in the .NET automatic installation package project (Visual Studio Installer Projects)

How to set the installation package to automatically install the .NET Framework environment in the .NET automatic installation package project (Visual Studio Installer Projects)

foreword

​Microsoft Visual Studio Installer Projects is a set of tools for creating installers, which is an extension of Microsoft Visual Studio. These tools allow developers to create and customize installers within Visual Studio to package and distribute their applications to users.
​Using Visual Studio Installer Projects, developers can configure various settings of the installer through a visual interface, and can use custom scripts and custom operations to meet specific installation needs. The tool is integrated in the Visual Studio development environment, enabling developers to develop applications and create installers in the same environment.
Visual Studio Installer Projects supports the creation of several types of installers, including MSI (Microsoft Installer) and ClickOnce. MSI is a common installer format that provides more advanced features and flexibility to perform more complex installation operations. ClickOnce is an easier way to install and is suitable for deploying and updating smaller applications.

​ This article mainly introduces how to set up the installation package to automatically install the .NET Framework environment in the .NET automatic installation package project (Visual Studio Installer Projects).

Create a new .NET WinForm project

For the convenience of demonstration, here I create a new WinForm APP (.NET Framework) console program. as the picture shows:

image-20230710101618708

Just put some controls on it. easy to demonstrate

image-20230710101935565

Install the Installer Project plugin

VS -> Extensions -> Manage Extensions -> Online -> Search "Install project" -> Select Microsoft Visual Studio Installer Projects to download and install:

image-20230707141756448

Create a new installation project (Setup Project)

VS -> Right click on the solution -> Add -> New Project -> Search template "Installer"

image-20230707140740302

Package type use
Setup project Create a Windows Installer project that can add files
Web setup project Create a Windows Installer Web project that can add files
Merge Module Project Create a Windows Installer merge module project that can add files
Setup Wizard Create a Windows Installer project with the help of the Setup Wizard

Here we choose Setup Project.

image-20230710102200057

Set WinForm Project output to Setup Project

This step mainly demonstrates the association between the .net project and the installer. Here I take the project output as an example to demonstrate. During the packaging process of the final installation package, the release output files such as DLL and EXE generated by the .net project will be automatically output to the installation package. Of course, according to your business needs, you can also add other types of files, assemblies, etc. to the installation package.

VS -> Right-click Setup -> Add -> Project Output

Set the configuration as follows, the output type selects Primary output (main output)

image-20230710102233371

NET Framework installation package

VS -> Right-click Setup -> Properties -> Enter the Setup property page dialog box -> Debug -> Prerequisite (prerequisite)

image-20230710102401703

Note: Debug and Release need to set the same prerequisites to avoid errors.

Enter the prerequisites dialog

image-20230710102750422

Select the .Net environment you want -> Specify the installation location of the system prerequisites: Download the system prerequisites from the same location as my application -> OK -> Apply -> OK

Generate the installation package

VS -> Select Release mode -> Right click Setup -> Generate

Generate error report and cause analysis:

The following error will appear when generating for the first time.

image-20230707145732498

There are two main problems here, one warning and one error. Let's solve it separately:

1. Solution to Warning

The warning message is as follows:

WARNING: The version of the .NET Framework launch condition ‘.NET Framework 4.7.2’ does not match the selected .NET Framework bootstrapper package. Update the .NET Framework launch condition to match the version of the .NET Framework selected in the Prerequisites Dialog Box.

Solution:

VS -> Right-click Setup -> Open the folder in File Explorer -> Open Setup.vdproj with a text editor -> Search for 4.7.2, change to 4.8 -> Regenerate, the warning disappears

image-20230707150357552

The running results are as follows. You can see that the Warning disappears and only Error remains.

image-20230707150552331

2. Error resolution

The error message is as follows:

ERROR: To enable ‘Download prerequisites from the same location as my application’ in the Prerequisites dialog box, you must download file ‘DotNetFX48\NDP48-x86-x64-AllOS-ENU.exe’ for item ‘Microsoft .NET Framework 4.8 (x86 and x64)’ to your local machine. For more information, see http://go.microsoft.com/fwlink/?LinkId=616018.
ERROR: General failure building bootstrapper
ERROR: Unrecoverable build error - 0x80004005

Analysis of the cause of the error:

Microsoft official explanation: How to: Include Prerequisites with a ClickOnce Application

Before you can distribute prerequisite software with a ClickOnce application, you must first download the installer package for these prerequisites to your development computer. When you publish an application and choose to download the prerequisites from the same location as my application, if the installation package is not in the package folder, you will get an error.

Solution:

Add the installer package using Package.xml

View the .NetFramework PackageFile information that needs to be installed

Open the Packages folder

By default, the path is on 64-bit systems C:\Program Files (x86)\Microsoft SDKs\ClickOnce Bootstrapper\Packages. as shown in the picture
image-20230707151206582

View configuration information for prerequisite folders

Open the folder of the prerequisites to be added, the folder corresponding to .net framework 4.8: DotNetFX48.

image-20230707152142904

Then open it with a text editor Product.xmlto view the files we need to download manually.

As shown in the figure, we can see that we need to manually download two PackageFile files:

NDP48-x86-x64-AllOS-ENU.exeandNDP48-Web.exe

image-20230707152314814

Download .NET Framework PackageFile

We can go to Baidu and download a few files and put them in the DotNetFX48 directory.

You can also go to Microsoft's official address to download: Download .NET Framework 4.8

image-20230710104342307

image-20230710105145373

Download the Chinese language pack

Go to zh-Hansthe folder:

image-20230707153259215

In a text editor, open the Package.xml file:

image-20230707153345926

image-20230710105343084

Let's continue to .NET Framework 4.8 to download the Chinese (Simplified) language pack and put it \Packages\DotNetFX48\zh-Hansin the directory

image-20230710110127909

Regenerate, the error disappears.

image-20230710110319373

After it is generated, there will be an additional DotNetFX48 folder.

image-20230707155442355

In this way, the installation package will automatically install the .Net Framework environment.

Guess you like

Origin blog.csdn.net/guigenyi/article/details/131641611
Recommended