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?

Community
  • 1
  • 1
Evgeniy Berezovsky
  • 16,237
  • 8
  • 74
  • 131
  • 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. – Cody Gray Apr 11 '12 at 05:28
  • @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... – Evgeniy Berezovsky Apr 11 '12 at 05:40

1 Answers1

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.

nvuono
  • 3,193
  • 23
  • 26
  • 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 http://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... – Evgeniy Berezovsky Apr 12 '12 at 02:08
  • @EugeneBeresovsky Works on XP because there you got default administrative access... – BerDev Mar 06 '19 at 07:34