How can I make Visual Studio precompile my C# assembly? It's a plain C# program -- no ASP. I just spent an hour going through the Microsoft garbage trying to figure this out. I'm sure it's just a compiler or linker switch, but there's no clue what it is in their "documentation". I'm trying to make the application avoid JITing, like what NGEN does.
Thanks,
Alan
Alan C BalkanyPosted Sep 26, 2007, 1:21 PM
I just found a link to a very detailed article on NGEN: http://community.bartdesmet.net/blogs/bart/archive/2005/09/01/3512.aspx
FYI
Alan C BalkanyPosted Sep 26, 2007, 1:08 PM
AlanPosted Sep 26, 2007, 12:56 PM
I don't think it's possible, Alan, to run ngen directly from Visual Studio.
There's no compiler or linker switch which would allow ngen to be run as the final part of the build process and, even if there was, you'd still have to run ngen on every client machine to install the native image in its GAC as you said yourself.
However, what you can do is to use a custom dll to automate installation on other machines. This article by Bob Powell describes how to do this (there is a switch to change from VB to C# code) and, although it was written for use with the .NET 1.1 version of ngen, I don't see why it shouldn't work with .NET 2.0 if you change the references appropriately:
http://www.bobpowell.net/prejit.htm
Alan C BalkanyPosted Sep 26, 2007, 11:54 AM
Thanks for the reply, but my question was how to make Visual Studio do the precompiling.
As I understand it, NGEN must be run on EVERY user's machine to put the assembly in the GAC. This complicates the installation process, and it seems like a better solution if Visual Studio does the precompiling once. Unfortunately, Microsoft has made it very difficult to obtain this information. (Maybe they're so proud of JITing they don't want people bypassing it.)
AlanPosted Sep 26, 2007, 11:48 AM
ngen.exe is in fact a command line utility so you have to leave Visual Studio itself and open a command window to use it.
If you have VS 2005 then from the desktop click: Start -> All Programs-> Microsoft Visual Studio 2005-> Visual Studio Tools->Visual Studio Command Prompt.
You'll then need to navigate to where your .NET executable resides and call ngen. As you'll probably know already from reading the docs, the basic command is something like:
ngen install myapp.exe