2

We have a C# project where the C# projects are compiled with TargetFrameworkVersion 4.7.2. For example, in the csproj file this is specified --

 <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>

The compiled and built exe is installed in a VM which has .net 4.6.1 installed. I see that installation is successful and the software is working fine. So can we safely say that projects built with 4.7.2 can execute when .netframework 4.6.1 installed. Or are there any issues to look out for here ?

user496934
  • 3,822
  • 10
  • 45
  • 64
  • We also found this in testing recently - I'm interested to hear the answer! (In our case we were testing what happens if we deploy a 4.7.2 click-once application to a client that only has 4.6.1 installed. We expected it to fail, but in fact it worked fine...) – Matthew Watson Apr 22 '19 at 08:51
  • 1
    I don't think it is guaranteed to work. Net uses dll libraries and when the libraries change the entry points and parameter lists may change with different versions. When Net gets updated not all the libraries change so if you are using libraries that did not change it will work. A lot of Net methods are just wrappers and call Windows dll so the wrappers will always work with same version of Windows. – jdweng Apr 22 '19 at 08:56
  • 2
    I think this is because .net framework from v4.0 share the same CLR, so unless you use some brand new feature of 4.7.2 - you may run on any framework 4.0+ – vasily.sib Apr 22 '19 at 08:57
  • I think this answers it. The project was built in .net 4.6.1 couple of years back and only last month targetframework version was updated to 4.7.2 without any code changes. Since we are not using any brand new APIs of 4.7.2, things work fine. Testing team also hasnt found any issue. – user496934 Apr 22 '19 at 09:01

1 Answers1

5

You can use supportedRuntime element in your app.config file, like

<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
    </startup>
</configuration>

It's possible, since they share the same CLR version 4.0. But you'll probably get a runtime exception, if using any specific features from .NET 4.7.2. Have a look at this thread for more details

Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
  • 1
    Aha! I just looked at all our ClickOnce apps and although the project settings have been changed to use .net 4.7.2, none of their App.Config files have been updated to reflect that change! Better get on that... – Matthew Watson Apr 22 '19 at 12:34