dos3.3.gho_.NET到处显然也意味着Windows 3.11和DOS

dos3.3.gho

dos3.3.gho

I often talk about how .NET Core is open source and runs "everywhere." MonoGame, Unity, Apple Watches, Raspberry Pi, and Microcontrollers (as well as a dozen Linuxes, Windows, etc) is a lot of places.

我经常谈论.NET Core如何是开源的并且可以在任何地方运行。 MonoGame,Unity,Apple Watch,Raspberry Pi和Microcontrollers(以及十几个Linux,Windows等)位于很多地方。

Michal Strehovský wants C# to run EVERYWHERE and I love him for it.

MichalStrehovský希望C#可以在任何地方运行,为此我爱他。

C# running on Windows 3.11

He recently got some C# code running in two "impossible" places that are now added to our definition of everywhere. While these are fun experiments (don't do this in production) it does underscore the flexibility of both Michals' technical abilities and the underlying platform.

最近,他在两个“不可能的”地方运行了一些C#代码,这些地方现在已添加到我们对“无处不在”的定义中。 尽管这些是有趣的实验(在生产中不要这样做),但它确实强调了Michals的技术能力和基础平台的灵活性。

在Windows 3.11上运行C# (Running C# on Windows 3.11)

In this 7 tweet thread Michael talks about how he got C# running in Windows 3.11. The app is very simple, just calling MessageBoxA which has been in Windows since Day 1. He's using DllImport/PInvoke to call MessageBox and receive its result.

在这个7条推文中, Michael讨论了如何在Windows 3.11中运行C#。 应用程序是非常简单,只需调用MessageBoxA这已经在Windows天以来他的使用的DllImport /的PInvoke调用MessageBox并且接收其结果

I'm showing this Windows 3.11 app first because it's cool, but he started where his DOS experiment left off. He's compiling C# native code, and once that's done you can break all kinds of rules.

我先展示这个Windows 3.11应用程序,因为它很酷,但是他从DOS实验中断的地方开始。 他正在编译C#本机代码,一旦完成,您就可以打破各种规则。

In this example he's running Win16...not Win32. However (I was alive and coding and used this on a project!) in 1992 there was a bridge technology called Win32s that was a subset of APIs that were in Windows NT and were backported to Windows 3.11 in the form of Win32s. Given some limitations, you could write 32 bit code and thunk from Win16 to Win32.

在此示例中,他正在运行Win16 ...而不是Win32。 但是,(我还健在并在其中编码并在项目中使用了它!)在1992年,存在一种称为Win32s的桥接技术,该技术是Windows NT中API的子集,并以Win32s的形式移植到Windows 3.11。 鉴于某些限制,您可以编写32位代码,然后从Win16转换为Win32。

Michal learned that the object files that CoreTR's AOT (ahead of time) compiler in 2020 can be linked with the 1994 linker from Visual C++ 2.0. The result is native code that links up with Win32s that runs in 16-bit (ish) Windows 3.11. Magical. Kudos Michal.

Michal了解到,CoreTR的AOT(提前)编译器在2020年提供的目标文件可以与Visual C ++ 2.0中的1994链接器链接。 结果是本机代码与在16位(ish)Windows 3.11中运行的Win32链接。 神奇。 Kudos Michal。

Simple Hello World C# app

在DOS上以8kb的速度运行C# (Running C# in 8kb on DOS)

I've blogged about self-contained .NET Core 3.x executables before and I'm a huge fan. I got my app down to 28 megs. It's small by some measurements, given that it includes the .NET runtime and a lot of accoutrements. Certainly one shouldn't judge a VM/runtime by its hello world size, but Michal wanted to see how small he could go - with 8000 bytes as the goal!

我以前在博客中介绍过独立的.NET Core 3.x可执行文件,而且我非常喜欢。 我的应用程序降到了28兆。 考虑到它包括.NET运行时和许多附件,因此从某些方面考虑,它很小。 当然,不应该根据虚拟机/运行时的大小来判断虚拟机/运行时,但是Michal希望看到自己可以达到多小-以8000字节为目标!

He's using text-mode which I think is great. He also removes the need for the garbage collector by using a common technique - no allocations allowed. That means you can't use new anywhere. No reference types.

他使用的文字模式我认为很棒。 他还通过使用一种通用技术消除了对垃圾收集器的需求-不允许分配。 这意味着您不能在任何地方使用新产品。 没有参考类型。

He uses things like "fixed char[]" fields to declare fixed arrays, remembering they must live on the stack and the stack is small.

他使用诸如“ fixed char []”字段之类的东西来声明固定数组,并记住它们必须存在于堆栈中并且堆栈很小

Of course, when you dotnet publish something self-contained, you'll initially get a 65 meg ish EXE that includes the app, the runtime, and the standard libraries.

当然,当dotnet发布独立的内容时,最初会得到一个65兆的EXE,其中包括应用程序,运行时和标准库。

dotnet publish -r win-x64 -c Release

He can use ILLinker and PublishedTrimmed to use .NET Core 3.x's Tree Trimming, but that gets it down to 25 megs.

他可以使用ILLinker和PublishedTrimmed来使用.NET Core 3.x的Tree Trimming,但这可以将其降低到25兆。

He tries using Mono and mkbundle and that gets him down to 18.2 megs but then he hits a bug. And he's still got a runtime.

他尝试使用Mono和mkbundle,将其降低到18.2兆,但随后遇到了一个错误。 而且他仍然有运行时。

So the only runtime that isn't a runtime is CoreRT which includes no virtual machine, just functions to support you.

因此,唯一不是运行时的运行时是CoreRT,它不包含虚拟机,仅提供支持您的功能。

dotnet publish -r win-x64 -c Release /p:Mode=CoreRT

And this gets him to 4.7 megs, but still too big. Some tweaks go to about 3 megs. He can pull out reflection entirely and get to 1.2 megs! It'll fit on a floppy now!

这使他达到4.7兆,但仍然太大。 一些调整到大约3兆。 他可以完全拉出反射并达到1.2兆! 现在适合放在软盘上!

dotnet publish -r win-x64 -c Release /p:Mode=CoreRT-ReflectionFree

This one megabyte size seems to be a hardish limit with just the .NET SDK.

仅使用.NET SDK,这一1兆字节的大小似乎是一个严格的限制。

Here's where Michal goes off the rails. He makes a stub reimplementation of the  System base types! Then recompiles with some magic switches to get an IL only version of the EXE

这是Michal摆脱困境的地方。 他对System基本类型进行了重新实现! 然后使用一些魔术开关重新编译以获得EXE的仅IL版本

csc.exe /debug /O /noconfig /nostdlib /runtimemetadataversion:v4.0.30319 MiniBCL.cs Game\FrameBuffer.cs Game\Random.cs Game\Game.cs Game\Snake.cs Pal\Thread.Windows.cs Pal\Environment.Windows.cs Pal\Console.Windows.cs /out:zerosnake.ilexe /langversion:latest /unsafe

Then he feeds that to CoreIT to get the native code

然后他将其提供给CoreIT以获取本机代码

ilc.exe zerosnake.ilexe -o zerosnake.obj --systemmodule zerosnake --Os -g

yada yada yada and he's now here

yada yada yada他现在在这里

"Now we have zerosnake.obj — a standard object file that is no different from object files produced by other native compilers such as C or C++. The last step is linking it."

“现在我们有了zerosnake.obj —一个标准的目标文件,与其他本机编译器(例如C或C ++)生成的目标文件没有什么不同。最后一步是链接它。”

A few more tweaks at he's at 27kb! He then pulls off a few linker switches to disable and strip various things - using the same techniques that native developers use and the result is 8176 bytes. Epic.

他在27kb时还有一些调整! 然后,他使用本地开发人员使用的相同技术,断开了一些链接器开关以禁用和剥离各种内容-结果为8176字节。 史诗。

link.exe /debug:full /subsystem:console zerosnake.obj /entry:__managed__Main kernel32.lib ucrt.lib /merge:.modules=.rdata /merge:.pdata=.rdata /incremental:no /DYNAMICBASE:NO /filealign:16 /align:16

a

一种

What's the coolest and craziest place you've ever run .NET code? Go follow Michal on Twitter and give him some applause.

您曾经运行过.NET代码的最酷最疯狂的地方是什么? 在Twitter上关注Michal,并给他鼓掌。

翻译自: https://www.hanselman.com/blog/net-everywhere-apparently-also-means-windows-311-and-dos

dos3.3.gho

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值