据我了解,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?
发布评论
评论(2)
这是不正确的。 EXE文件仅包含一个小存根,该存根会导致操作系统将其加载到.NET运行时。或者对于自我包含的组件,我猜它包含整个运行时。无论如何,其余的.exe文件是IL代码,该文件将由运行时加载并编译为机器代码。
在Linux上,我认为您只是直接将.NET运行时调用,以作为参数。 IE
dotnet myassembly.exe
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
.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/