Search code examples
c#.net.net-framework-version

Can C# projects that have 4.7.2 target framework version run on .net 4.6.1


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 ?


Solution

  • 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