none
Enable App to target .NET 3.5 and .NET 4? RRS feed

  • Question

  • Hi All,

     

    I have a Visual Basic application and i'm using VS 2017. The app was originally created to target .NET Framework 3.5. I would like to allow the app to target .NET 3.5 or/and  4.0/4.5 so it could run on a machine with .NET Framework 3.5 or a machine with just .NET Framework 4.0 or 4.5.

     

    I was reviewing this article: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-configure-an-app-to-support-net-framework-4-or-4-5 it seems like this should be possible by editing the app.config file. I edited the app.config file and added the following lines to allow multi framework targeting based on the article.

     

                  <startup> 

                               <supportedRuntime version="v4.0"/>

                               <supportedRuntime version="v2.0.50727"/>

                  </startup>

     

    What happens is the app works on a machine with .NET framework 3.5 installed, but it won’t run on a Windows 10 machine with just .NET Framework 4.5 installed (Exact version installed is: 4.7.02046). I get the prompt you need .NET 3.5 and prompted to download:


    Any idea what I may be missing here?


    Justin Chalfant | My Blog | LinkedIn | Please mark as helpful/answer if this resolved your post


    Saturday, July 22, 2017 8:26 PM

All replies

  • Justin,

    Why not set the framework to 3.5 and let it go at that?

    3.5 will run on anything 3.5 and above after all, so ...?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Saturday, July 22, 2017 8:32 PM
  • The project currently is set to .NET Framework 3.5 see picture. Not sure if there's something else causing it not to run on a machine with .NET 4.5. I also tried commenting out the <supportedRuntime> element completely in the app.config and just have this set in the UI and the .NET 4.5 machine still prompts to install .NET 3.5.

    If I run it on a machine with 4.5 I get the prompt to download .NET 3.5


    Justin Chalfant | My Blog | LinkedIn | Please mark as helpful/answer if this resolved your post

    Saturday, July 22, 2017 8:52 PM
  • The project currently is set to .NET Framework 3.5 see picture. Not sure if there's something else causing it not to run on a machine with .NET 4.5. I also tried commenting out the <supportedRuntime> element completely in the app.config and just have this set in the UI and the .NET 4.5 machine still prompts to install .NET 3.5.

    If I run it on a machine with 4.5 I get the prompt to download .NET 3.5


    Justin Chalfant | My Blog | LinkedIn | Please mark as helpful/answer if this resolved your post

    That's odd - I wouldn't expect that.

    Hopefully someone else here has seen this before, so be patient. ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Saturday, July 22, 2017 8:54 PM
  • Alright so found a little more out for this. I discovered if I copy the MyApp.exe.config that contains the <supportedRuntime> to the same folder the MyApp.exe on the target machine it does run on a machine with just .NET 4.5. The issue is the app is portable so in general it won't contain the MyApp.exe.config in the same folder. Is there anyway to embed this into the code rather than having to have the XML in the same folder as the EXE?

                  <startup> 

                               <supportedRuntime version="v4.0"/>

                               <supportedRuntime version="v2.0.50727"/>

                  </startup>

    I also discovered if I set the OnlyUseLatestCLR value to 1 it will run the app even without the config file in the same folder as the exe.


    Justin Chalfant | My Blog | LinkedIn | Please mark as helpful/answer if this resolved your post


    Sunday, July 23, 2017 5:21 PM
  • Alright so found a little more out for this. I discovered if I copy the MyApp.exe.config that contains the <supportedRuntime> to the same folder the MyApp.exe on the target machine it does run on a machine with just .NET 4.5. The issue is the app is portable so in general it won't contain the MyApp.exe.config in the same folder. Is there anyway to embed this into the code rather than having to have the XML in the same folder as the EXE?

                  <startup> 

                               <supportedRuntime version="v4.0"/>

                               <supportedRuntime version="v2.0.50727"/>

                  </startup>

    I also discovered if I set the OnlyUseLatestCLR value to 1 it will run the app even without the config file in the same folder as the exe.


    Justin Chalfant | My Blog | LinkedIn | Please mark as helpful/answer if this resolved your post



    I am not aware of a way to do what you describe exactly.

    However I guess am not sure what you mean by "portable"?

    Do you have a setup program to install on the system? What is the target system? You can distribute 3.5 with your app. Is there some reason you do not?

    I guess useLegacyV2RuntimeActivationPolicy does not apply for what you want.

    https://msdn.microsoft.com/en-us/library/ff770241%28v=vs.100%29.aspx?f=255&MSPPError=-2147217396

    Monday, July 24, 2017 12:17 AM
  • Hi Justin,

    .NET Framework 1.0, 1.1, 2.0, 3.0, and 3.5 apps do not automatically run on the .NET Framework 4 or later, and in some cases, the user may receive an error and may be prompted to install the .NET Framework 3.5. The activation behavior may also depend on the user’s operating system, because  different versions of Windows system include different versions of the .NET Framework. If your app supports both the .NET Framework 3.5 and 4 or later, we recommend that you indicate this with multiple entries in the configuration file to avoid .NET Framework initialization errors. For more information, see Versions and Dependencies.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 24, 2017 5:51 AM
    Moderator
  • Justin, 

    As you so well documented, .NET Framework 1.0, 1.1, 2.0, 3.0, and 3.5 apps do not automatically run on the .NET Framework 4 or later, 

    That is exactly why you did it this way. 

    However, nobody can prevent that users do things which you don't expect they do. Maybe they removed the framework by hand. Therefore if you get this kind of problems, than make yourself sure the user did not do that (And don't always listen what they tell. Often they tell that they did not do it and at the end when it is proven tell they did not understand you)


    Success
    Cor

    Monday, July 24, 2017 9:15 AM
  • I know this is quite old, but I'm currently facing the same issue. 

    I can give a bit of context to clarify my use case and an argument for allowing this info to be embeded somehow in the exe.

    In my case, the app IS the installer - a custom-made installer, with custom branding elements, and a specific workflow, since it had been hard / impossible to do some of the things we wanted to in third party vender packages.

    I'm currenlty building it as a 3.5 app, since this would support use on win 7, win 8, and win 10 machines considering that these are the OSs that we know our clients have (and we can't force them to upgrade), and that typically have a version of .net greater or equal to 3.5 installed by default.

    Ideally, they'd pull this executable installer from our web site and run it, whichever the OS. I don't expect my clients in this domain to understand what an app.config is and therefore mandating a second file to live side by side would definitely create a mountain of customer service requests. Ideally it would just be download, click to run, and move on.

    Currently, testing with the app.config in place like the one above (with v2 and v4 supported), it runs and the 3.5 feature is not required to be installed to get everything in place. Without it, though, on a modern Win 10 machine that has 3.5 off, the user will first need to install 3.5 (can't really skip it even if the dialog suggests it) and then click once again on the app to run it (won't start automaticaly after 3.5 finishes it's installation).

    Would there be any way of adding this info into the exe, even if through IL manipulation or some roslyn / msbuild directives?

    Embedding the app.config through the file / build properties adds it to the .exe, but it's never read. Renaming it to exe.config so that it gets embedded into it with the expected naming convention also doesn't solve the issue. How, Who and When does the executable decide to search for the config file and load those settings?

    Friday, September 27, 2019 8:59 AM
  • I know this is quite old, but I'm currently facing the same issue. 

    I can give a bit of context to clarify my use case and an argument for allowing this info to be embeded somehow in the exe.

    In my case, the app IS the installer - a custom-made installer, with custom branding elements, and a specific workflow, since it had been hard / impossible to do some of the things we wanted to in third party vender packages.

    I'm currenlty building it as a 3.5 app, since this would support use on win 7, win 8, and win 10 machines considering that these are the OSs that we know our clients have (and we can't force them to upgrade), and that typically have a version of .net greater or equal to 3.5 installed by default.

    Ideally, they'd pull this executable installer from our web site and run it, whichever the OS. I don't expect my clients in this domain to understand what an app.config is and therefore mandating a second file to live side by side would definitely create a mountain of customer service requests. Ideally it would just be download, click to run, and move on.

    Currently, testing with the app.config in place like the one above (with v2 and v4 supported), it runs and the 3.5 feature is not required to be installed to get everything in place. Without it, though, on a modern Win 10 machine that has 3.5 off, the user will first need to install 3.5 (can't really skip it even if the dialog suggests it) and then click once again on the app to run it (won't start automaticaly after 3.5 finishes it's installation).

    Would there be any way of adding this info into the exe, even if through IL manipulation or some roslyn / msbuild directives?

    Embedding the app.config through the file / build properties adds it to the .exe, but it's never read. Renaming it to exe.config so that it gets embedded into it with the expected naming convention also doesn't solve the issue. How, Who and When does the executable decide to search for the config file and load those settings?

    One problem is if you only look at old threads you only get old information. :)

    "I'm currenlty building it as a 3.5 app, since this would support use on win 7, win 8, and win 10 "

    If you are using win7 and above you can use .net 4 and above? So why are you using 3.5? Is there something else that requires it like old software that requires 3.5?

    If so you can use useLegacyV2RuntimeActivationPolicy to make your app drop to .net 3.5 see:

    https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/startup/startup-element

    Its a simple change to app.config to add the legacy support.

    But you dont need to do anything to run on win7 and up with .net 4.5+. You can still compile to x86?


    Friday, September 27, 2019 9:20 AM
  • Thanks for the reply @tommutworain. My description of the choice for 3.5 might be a bit misleading. I don't need 3.5, really. There is nothing specific to that version of the FW that I need to use.

    The choice of .NET 3.5 is, and considering i'm building an installer, is that that would be the minimum I would need to run the exe on a clean machine (fresh install on a computer the client acquires). 3.5, being something that is on in older Windows versions (but no longer in win 10) would be sufficient to run the process. considering I'm only using things also available in .NET 4+, and that being included in win10, it could run there too. 

    I do have prerequisites to be able to run the app that will be setup by the installer (like net 48 and other stuff) but my installer adds that for me. And for a simple user experience and workflow, I only want to give clients a single exe, without demanding they add anything "extra" like an app.config.

    As I mentioned, adding the app.config next to the .exe gets it running without requesting the installation of 3.5 - everything i'm using is .net 4 compatible. This is a case where embedding the supported runtimes definition into the .exe somehow would make sense and be benificial.

    Also, I've seen a lot of mentions that the app.config is designed to allow to override values, but in this how / where are the supportedRuntime values defined? If I could set them in the exe somehow (even if post build), could I avoid needing the app.config?

    Tuesday, October 1, 2019 4:29 PM