问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/10100248/is-it-possible-to-pre-generate-ngen-images-so-customers-dont-have-to