简体   繁体   中英

How do I include .NET Framework alongside my project installation?

I have a Windows service built using .NET Framework (version 4.6.2). It was made using the "Windows Service (.NET Framework)" template in Visual Studio 2017. For reference, I followed this guide .

A custom installer will be made to install/update/maintain this Windows service on client machines. Here's an overview of the installer:

  • User enters some information into a form/UI.
  • Validate user input.
  • Place the Windows service project binaries in a user-specified directory.
  • Run the command to install the Windows service. It will use the Windows sc utility.
  • Create a registry key. Insert values into this registry key.
  • Ensure .NET Framework 4.6.2 is installed on the machine. Install it if it is not already installed.

As far as I can tell, when the service is started, .NET Framework 4.6.2 needs to already be installed on the machine for the service to work.

How do I make certain that the client's machine has .NET Framework 4.6.2 installed on it?

Also, will other versions of .NET Framework - for example version 4.8 - already installed on the machine cause issues?

I did some searching online, but haven't found any solutions for my situation. This solution only works if we decide to use the Visual Studio Installer project for our installer. Self-contained deployments apparently only work for projects based on .NET Core, not .NET Framework.

Although we haven't yet implemented our custom installer, after some research, here is what we will most likely do:

  • Include the offline installer for .NET Framework (in our case, we need version 4.6.2 ) within our custom installer.
  • Have our custom installer check for an existing version of .NET Framework. See this document for details on determining an installed version of .NET Framework.

    • If the client has .NET Framework version 4.6.2. (or greater) installed, then move on with the installation process.
    • If the client has an older version of .NET Framework installed, then ask them if they want to update to version 4.6.2. If they decline, abort the custom installer. If they choose to update to .NET Framework version 4.6.2, then we will invoke the offline installer. See the basic code example below invoking the offline installer:

       // NOTE: This code is just a crude example. // Invoke the offline installer. System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C path\\\\to\\\\offline\\\\installer\\\\NDP462-KB3151800-x86-x64-AllOS-ENU.exe"; process.StartInfo = startInfo; process.Start(); process.WaitForExit(); // Handle the exit code. if (process.ExitCode == ...) { ... }

References

  • This document provides an introduction to redistributing the .NET Framework.
  • This document provides details on redistributing the .NET Framework.
  • This document contains information about minimum system requirements for .NET Framework.
  • Although more IT-oriented, this tutorial and this tutorial contain useful details about installing .NET Framework.

Related

The following was found during some of my testing/research:

  • By default, these operating systems have the following versions of .NET Framework installed:
    • Windows 7 SP1 – .NET Framework version 3.5.30729.5420
    • Windows 10 November 2019 Update (Version 1909) – .NET Framework version 4.8
    • Windows Server 2012 R2 Standard (Version 6.3.9600) – .NET Framework version 4.5.1
    • Windows Server 2019 (Version 10.0.17763; aka Version 1809) – .NET Framework version 4.7.2
  • With recent updates ( circa February 2020 ), these operating systems have the following versions of .NET Framework installed:
    • Windows 7 SP1 – .NET Framework version 4.8
    • Windows 10 November 2019 Update (Version 1909) – .NET Framework version 4.8
    • Windows Server 2012 R2 Standard (Version 6.3.9600) – .NET Framework version 4.8
    • Windows Server 2019 (Version 10.0.17763; aka Version 1809) – .NET Framework version 4.7.2

Troubleshooting

  • This document contains information on how to troubleshoot .NET Framework installation/un-installation.
  • This document contains information on troubleshooting an error related to starting an application dependent on .NET Framework.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM