How to include NGEN's invoke in a publish process? RRS feed

  • Question

  • User1993186009 posted

    For my web application I need to provide the response right after deployment as fast as it possible. To achieve this goal I would like to add NGEN to my publish configuration. How can I do it via Visual Studio or by manual editing of all involved .CSPROJ files? 

    Thursday, October 3, 2019 3:52 PM

All replies

  • User753101303 posted


    I would perhaps try first few IIS settings if not done yet such as https://www.nickedeye.com/iis-keep-website-alive-always-running/

    Thursday, October 3, 2019 5:10 PM
  • User1993186009 posted


    Tried this , didn't help too much. I still need to find a way of running NGEN while publishing my app. Any ideas?

    Thursday, October 3, 2019 8:28 PM
  • User283571144 posted

    Hi Gatwick,

    If you want to know how to run command after the web application has published successfully.

     I suggest you could consider adding below config into the csproj.

    <Target Name="CustomPostPublishActions" AfterTargets="GatherAllFilesToPublish">
    <Message Text="This is custom target" Importance="high" />
    <Exec Command='yourcommand line codes'/>

    Best Regards,


    Friday, October 4, 2019 2:26 AM
  • User1993186009 posted

    Ok, in this case the next step comes down to these 

    yourcommand line codes

    Do you have any ideas what I should write there? I want to avoid explicit mentioning of all produced DLLs.

    Friday, October 4, 2019 10:37 AM
  • User753101303 posted

    You could first start by hand and run ngen for all files found in your bin folder and see then, what happens. Most sources seems to tell it is not that significant.

    I would start first to check what happens. If I remember you have "health checks" for that. Also I believe you can ask for launching the site once dpeloyed at least from VS.

    Also it happens the time is spent in user code depending on what you are doing when the app starts...

    Friday, October 4, 2019 11:18 AM
  • User753101303 posted

    ngen is described here: https://docs.microsoft.com/en-us/dotnet/framework/tools/ngen-exe-native-image-generator

    For now you could just try this manually in your bin folder but accordng to https://www.eidias.com/blog/2017/1/4/does-it-make-sense-to-ngen-compile-your-aspnet-mvc-application it doesn't seems to make a significant difference.

    I would look more closely at what happens for example you can still have a compilation step (even for a "precompiled app", you can still have some stuff being precompiled on the fly). If I remember you have "ASP.NET Health" events allowing to cach this kind of things.
    Sometimes it turns out just to be something being done explictely in the code and that is forgotten (loading images in a cache or whatever rather than waiting for the first use).

    Friday, October 4, 2019 1:05 PM