.net Framework 4.0 installation and Ngen RRS feed

  • Question

  • Hi.

    I have created application that is using .Net 4.0 and now I need to make its installation package.
    Part of my application installation is of course to check if .Net 4.0 Client profile is installed and if not it will be automatically installed using official microsoft .Net installer dotNetFx40_Client_x86_x64.exe

    Then after .net installation is finished my application is installed.

    Problem is that when user starts my application soon after installation (which is almost always the case) its startup time is very long.

    Reason is that installed .Net Framework is not yet "precompiled" with Ngen...

    If I understood it correctly, instead there is created service "Microsoft .NET Framework NGEN" for version 4.0 32bit and another for 64bit CLR optimization and this service is configured to start automatically and when PC is idle do this ngen optimization on framework assemblies.

    But it means that first impression for user is that (after long .Net installation) my application starts very slow - like 20 seconds instead of maybe 5 seconds when Ngen service finally finish his job.

    So my question is... Is there some switch that I can use when starting dotNetFx40_Client_x86_x64.exe so that "Ngen /update" will be performed already during .Net installation?

    Or do I have to somehow run that Ngen on Framework "manually" during my installation process?
    Wednesday, December 15, 2010 4:35 PM


All replies

  • Hi Michal Szalai,
    Welcome to MSDN Forum.
    According to your description of the problem, the issue you are experiencing is:
    1. You are making a installation package for your application with .NET 4.0.
    2. Both the .NET Client Profile and your application can be successfully installed during the installation.
    3. The startup time of your application is very long, and the cause of this is the .NET Framework installation not fully installed with "Ngen /update".
    4. You want to find some switch or some other ways to install "Ngen /update" during your application is being install. And limit the start time of your application.
    If I have misunderstood anything, please feel free to let me know.
    I've found the .NET Framework Deployment Guide for Developers might be help. It introduces some command-line options could be use when you run the .NET Framework 4 redistributable installation program from the command line.
    I hope this will help resolve your problem. If anything is unclear, please free feel to let us know.
    Best Regards,
    Andrew Wu
    Friday, December 17, 2010 4:58 AM
  • Hi Andrew.

    Thank you for answer. There seems to be no such command line option that will ensure "Ngen update" to be called during .Net installation.

    But even calling "ngen update" helped to speed up my application startup on freshly installed .Net on my PC from 15 seconds to 3 seconds I found some other way:

    When I changed target platform for my application from Any CPU to x86 the difference between ngen-ed framework or not ngen-ed is not 15->3 seconds but only 5->3 seconds so those 5 seconds are much better for me.


    I don't know why this happens, but I decided to build my application as x86 instead of Any CPU.


    Friday, December 17, 2010 8:44 AM
  • Dear Michal Szalai,

    Thank you for your reply.

    I need to clarify one point with you. Is you using ngen.exe in your application?

    If so, you might use ngen update [/queue] to update native images that have become invalid. You can refer to follow links for the usage of ngen.exe:

    If not, would you please give more information, about why you estimate the application startup slowly is caused by Ngen? Because all the research I've done is focus on ngen. I need to confirm it is the Ngen that cause this issue.

    And as your issue is more related with Setup & Deployment Projects, you can post your problem on this forum So that you can get better and quicker response as there are more experts on this kind of issues.

    Thank you for your understanding and support.

    Best Regards,
    Andrew Wu

    Andrew Wu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Larcolais Gong Monday, December 27, 2010 5:21 AM
    Tuesday, December 21, 2010 8:00 AM
  • Hi Michal Szalai,

    Any update? If you have any questions, please feel free to let me know.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 23, 2010 6:15 AM