简体   繁体   中英

How to deploy windows application to an older .NET Framework

I am building a windows application from Visual studio 2017 using C#. I have a windows 10 system and my .NET Framework by default is 4.7. But I want to run this application in a system which is windows 7 and uses 4.5 .NET Framework.

Therefore, while building this application I have change it's target framework to 4.5, also I have change its supported Runtime from app.config file.

在此处输入图片说明

在此处输入图片说明

Below is my app.config file:

  <?xml version="1.0" encoding="utf-8"?>
        <configuration>  
    <configSections>
    </configSections>
        <startup>
          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>      
        </startup>    
        </configuration>

Now when I try to run this application in windows 7, I get the error message "This setup requires the .NET Framework version v4.6.1. Please install the .NET Framework and run this setup again. The .NET Framework can be obtained from the web. Would you like to do this now?. Then when I hit "Yes" button. I get an error "Component Microsoft .NET Framework 4.6.1(x86 and x64) has failed to install with the following error message" " A failure occured attempting to install the Microsoft .NET Framework 4.6.1"

在此处输入图片说明

在此处输入图片说明

There are at least 2 things happening here.

Installation requirements

It appears that the target (Windows 7) machine might not have a 4.5 or higher version of the .NET Framework installed. If that's true, the installation program will try to install v4.6.1 because that's the in-place upgrade for versions 4.0, 4.5, 4.5.1, and 4.5.2. (as outlined here ).

Alternatively one or more libraries or other components used by your application need version 4.6.1, even though your core application code doesn't.

Installation issue

The installation problem is likely a separate issue. Have you checked the setup log mentioned in the error message to see more details?

I fixed it, I am posting it incase if someone may have the same issue. My problem with the client machine was, it was window 7 but without any service pack installed. Where else to install the .NET Frame work V4.6.1 your system must be window 7 with SP1. I simply installed the SP1 to client machine window 7 and problem got resolved and I was able to install .NET Framework v4.6.1 hence my software is running. Here is the link . But I haven't figure out how to make my windows application target the desired .NET Framework when building it from VS 2017.

You have to check if there are any NuGet Packages, using .NET 4.6.1. If this is the case, you have to downgrade them aswell.

查看引用,也许某些库是.NET Framework版本v4.6.1

How do you build an installer of your application? Maybe there you have some condition which checks installed .NET Framework version.

You have to install .NET Framework version v4.6.1 on your machine. Find the installer from the below link: https://www.microsoft.com/en-us/download/details.aspx?id=49982

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