Is it possible to pre-generate NGen images so customers don't have to?
Asked Answered
I

1

9

Our app, distributed via ClickOnce, takes 10.8 seconds on average to start up. After running ngen on the .exe (in the directory that ClickOnce installed it into), it starts up in 6.4 seconds on average. This is obviously a huge speedup (40%) and I would like to make use of ngen-ification if possible.

Ron's answer to Is it possible to use NGen with ClickOnce deployment? shows how it can be done on the customer's machine, assuming I guess he runs Windows XP, as it wants Administrator rights on my Windows 7 box, so that does not seem like a generic solution.

Furthermore, ngen takes 40 seconds on my box to compile all assemblies belonging to that app.

So ideally, I'd like to pre-ngen our app for all (major) architectures as part of the build process, so it could be shipped to the customer without the user having to accept an "ok to execute as admin?" popup and then wait 40 seconds.

Is that possible?

Inexperienced answered 11/4, 2012 at 5:21 Comment(2)
The NGen output is architecture-specific. And since it's unlikely that your build machine matches the production machine(s), this probably won't work like you're hoping.Trochaic
@CodyGray As mentioned in my question, I'd be willing to pre-ngen for all major architectures. If we did x86 and amd64 only that should cover 95% of customers, I guess...Inexperienced
F
9

You can't do this without administrative access on Windows 7.

The problem isn't the actual ngen generation of the native image but the installation into the native image cache (C:\windows\assembly\nativeImages_v#xxxxxxxxx) that requires administrative permissions. So even if you found a way to pre-generate the native images for all the target architectures you would not be able to get them into the appropriate location for the runtime to consider using them.

You can't just place them side-by-side with your regular binaries because then they wouldn't be managed properly--you'd get into trouble when certain security policy changes are made, .net framework updates are applied or other changes are made to referenced assemblies that invalidate the native images and would require an "ngen update" command to be run. Microsoft just doesn't appear to support the use-case of ngen with ClickOnce deployment at this time.

Fabre answered 11/4, 2012 at 6:4 Comment(2)
Something (google) tells me you are right, but let's wait a little bit, maybe something turns up. After all, despite MS' claims to the opposite, the answer to stackoverflow.com/questions/443955 showed that it is possible, at least for Windows XP. Granted, XP is not something a ClickOnce-deployed app should rely on these days...Inexperienced
@EugeneBeresovsky Works on XP because there you got default administrative access...Haze

© 2022 - 2024 — McMap. All rights reserved.