.NET 和输出文件扩展名
如果应用程序采用 MSIL 格式,为什么 Visual Studio 将其编译为可执行文件?难道不应该像java那样将代码编译成.class文件吗?
Why Visual Studio compiles an application to an executable if it's in the MSIL format? Shouldn't it be like java that compiles the code to a .class file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.NET“可执行文件”实际上是一个微小的_un_托管存根可执行文件,它创建一个AppDomain,实例化您的启动.NET对象并调用它。
.NET dll 相当于 java .class
编辑: -----
Jb Evain 在注释中指出 .NET dll 还包含非托管存根。
存根只是跳转到 mscoree.dll 中执行实际工作的适当入口点。
CorExeMain
用于 exe,CorDllMain
用于 dll。a .NET "executable" is really a tiny _un_managed stub executable that creates an AppDomain, instantiates your startup .NET object and calls into it.
a .NET dll would be the equivalent of a java .class
Edit: -----
Jb Evain points out in comments that .NET dlls also contain an unmanaged stub.
The stub just jumps to the appropriate entrypoint in
mscoree.dll
that does the actual work.CorExeMain
for exe's andCorDllMain
for dll's.因为 .exe 对于操作系统来说意味着某些东西 - Windows 不需要注册另一个可执行类型来运行。 .EXE 文件可以在“运行”菜单、命令行和 shell 中“正常工作”。
但可能更重要的是,因为人们已经开始期待 .exe 文件的行为。我的意思是,您已经使用 .EXE 文件作为 MS 系统上的主要可执行文件格式已有 30 年的时间了。如果他们将可执行的 .net 应用程序编译为“.CLR”扩展名,那么并不是每个人都知道如何使用它,这可能会减慢 .Net 的采用,尤其是在早期......
Because .exe means something to the OS - Windows doesn't have to register another executable type to run. .EXE files "just work" from the Run menu, the command line, and the shell.
But probably more importantly, because people have come to expect the behavior of a .exe file. I mean you've used .EXE files as the main executable file format on MS systems for the better part of 30 years now. If they compiled executable .net apps to, say, a ".CLR" extension, not everyone would know what to make of it, and that could have slowed the adoption of .Net, especially in the early days...