了解.NET编译

发布于 2025-02-01 11:45:38 字数 209 浏览 3 评论 0 原文

据我了解,NET概念,首先将源代码转换为汇编(IL代码+META数据),该组件通过CLR的JIT编译器将其编译为目标机上的机器代码。 但是,我无法真正将这些概念与在C#项目上工作时看到的内容相匹配。 当我构建一个项目时,我会收到一个.EXE文件,我认为这是可执行的机器代码。 IL存储在哪里?我可以访问它并将其传输到其他平台,例如Linux吗?

总而言之,有人可以纠正我的理解并解释输出吗?

As far as I understand .NET concepts, the source code is first translated into an Assembly (IL code+meta data), which is compiled to machine code on the target machine with the CLR's JIT compiler.
However I cannot really match these concepts to what I see when working on a C# project.
When I build a project I get an .exe file, which I assume is the executable machine code. Where is the IL stored? Can I access it and transfer it to a different platform e.g. to Linux?

To sum up, could somebody correct my understanding and explain the outputs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍暮颜 2025-02-08 11:45:38

当我构建一个项目时,我会得到一个.exe文件,我认为这是可执行的机器代码

这是不正确的。 EXE文件仅包含一个小存根,该存根会导致操作系统将其加载到.NET运行时。或者对于自我包含的组件,我猜它包含整个运行时。无论如何,其余的.exe文件是IL代码,该文件将由运行时加载并编译为机器代码。

在Linux上,我认为您只是直接将.NET运行时调用,以作为参数。 IE dotnet myassembly.exe

When I build a project I get an .exe file, which I assume is the executable machine code

This is incorrect. The exe file just contains a small stub that causes the OS to load it in the .net runtime. Or for self contained assemblies I guess it contains the entire runtime. Regardless, the rest of the .exe file is IL-code that will be loaded by the runtime and compiled to machine code.

On linux I think you just invoke the .net runtime directly with you assembly as the argument. I.e. dotnet myAssembly.exe

疯到世界奔溃 2025-02-08 11:45:38

.NET组件中没有装配代码。

.NET程序将转换为.NET组件,该组件是包含中间字节码的.exe或.dll。请参阅CIL

Visual Studio将.NET组件放在您的项目 /bin或 /bin /preame中)。您可以更改此路径。

dll或.exe是在引用文件夹中生成的组装文件。

只要Plataform支持框架版本,这两个文件都可以在Linux上运行。

完整的.NET框架仅适用于Windows,但是单声道和Core被移植到Linux。

There is no assembly code in .net assemblies.

.Net programs are converted to a .NET Assembly, which is an .exe or .dll that contains intermediate bytecode. See CIL

Visual Studio will place the .NET Assemblies in your project's /bin or /bin/Release). You can change this path.

The dll or .exe are the assembled files which are generated inside the cited folders.

Both files can run on linux as long as the framework version is supported by the plataform.

Full .net framework is only for windows, but mono and core are being ported to linux.

https://learn.microsoft.com/en-us/dotnet/standard/assembly/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文