如何编译与ngen.exe以及如何运行生成的本地代码? [英] How to Compile with ngen.exe and How to run the native code that is generated?

查看:490
本文介绍了如何编译与ngen.exe以及如何运行生成的本地代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要编译使用NGEN命令行对特殊目的C#程序。所以,我在创建一个VS2010控制台应用程序,并把它命名为ngentest。因此,通过NEMEngentest.vshost.exe文件中的vs2010\projects\\\
gentest\bin\debug被创建。
我用这个文件在Visual Studio 2010命令提示符下NGEN命令参数,如下所示:

I want to compile a c# program using ngen command line for a special purpose. So I create a console application in vs2010 and named it "ngentest". So a file by neme "ngentest.vshost.exe" is created in "vs2010\projects\ngentest\bin\debug". I used this file as a ngen command argument in Visual Studio 2010 command prompt, as follows:

"ngen "c:\documents\vs2010\projects\ngentest\bin\debug\ngentest.vshost.exe"

但我这样做的时候,我无法接收公钥,并在任何地方我找不到任何集会!
如果创建我的程序集,它在哪里?我怎么可以找到它?如何我可以运行(与命令,或者......!)让我的输出?

but when I do this, I can't receive PublicKeyToken and I couldn't find any assembly in anywhere! if my assembly is created, where it is? and how I can find it? I How I can run it(with command, or....!) to get my output?

否则,当我建立我的项目,构建从构建menue NGEN从VS,某些文件中提到directiry被创造,其中之一的是ngentest.exe。

otherwise when I build my project with build ngen from Build menue from VS, some file were created in mentioned directiry, and one one of them is ngentest.exe .

推荐答案

当您编译C#代码,它被编译成IL程序集。而NGEN需要IL总成作为输入,并安装组件和它的依赖到机映像缓存。

When you compile your C# code, it gets compiled into an IL assembly. And NGEN takes IL assembly as an input and installs the assembly and its dependencies into Native Image Cache.

有关您的例子二进制,你需要打开一个管理员VS COMAND promtp,然后键入以下

For your example binary, you need to open an admin VS Comand promtp, then type the following

NGEN安装ngentest.exe

这将安装你的EXE和DLL文件的依赖到机映像缓存。

This would install your exe and its dependency dlls into Native Image Cache.

然后,当你运行你的exe文件,.NET运行时将加载和运行本机映像安装到机映像缓存。您不需要采取任何额外的步骤有.NET运行本机图像。运行时检查机映像缓存,看看是否有对于IL装配一个有效的本机映像。

Then when you run your exe, .NET runtime will load and run the native image installed to Native Image Cache. You don't need to take any extra step to have .NET run the Native Image. The runtime checks the Native Image Cache to see if there is a valid Native Image for the IL assembly.

您可以验证本机映像是通过输入以下命令安装

You can verify that a native image is installed by typing the following command:

NGEN显示ngentest.exe

请参阅的 http://blogs.msdn.com/b/junfeng/archive/2007/02/ 18 /原生图像loading.aspx 对本机映像加载更多的信息。

See http://blogs.msdn.com/b/junfeng/archive/2007/02/18/native-image-loading.aspx for more info on Native Image loading.

注意ngentest.vhost.exe是VS创建一个神器提供更好的调试经验。它是用来通过VS.你不应该使用对于NGEN或就此而言什么。请看问题:什么是vshost.exe文件的目的获得更多信息。

Note that ngentest.vhost.exe is an artifact created by VS to provide better debugging experience. It is used by VS. You shouldn't be using that for NGEN or anything for that matter. See the question: What is the purpose of vshost.exe file? for more info.

这篇关于如何编译与ngen.exe以及如何运行生成的本地代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆