I've been using ILMerge and various hacks to merge/squish executables together for well over 12 years. The .NET community has long toyed with the idea of a single self-contained EXE that would "just work." No need to copy a folder, no need to install anything. Just a single EXE.
我使用ILMerge和各种技巧将可执行文件合并/压缩在一起已经超过12年了。 .NET社区长期以来一直在想一个可以“正常工作”的自包含EXE的想法。 无需复制文件夹,无需安装任何东西。 只是一个EXE。
While work and thought continues on a CoreCLR Single File EXE solution, there's a nice Rust tool called Warp that creates self-contained single executables. Warp is cross-platform, works on any tech, and is very clever
尽管在CoreCLR单个文件EXE解决方案上的工作和思想仍在继续,但是有一个很好的Rust工具称为Warp ,它可以创建独立的单个可执行文件。 Warp是跨平台的,可以在任何技术上使用,并且非常聪明
The Warp Packer app has a slightly complex command line, like this:
Warp Packer应用程序具有一个稍微复杂的命令行,如下所示:
.\warp-packer --arch windows-x64 --input_dir bin/Release/netcoreapp2.1/win10-x64/publish --exec myapp.exe --output myapp.exe
Fortunately Hubert Rybak has created a very nice "dotnet-warp" global tool that wraps this all up into a single command, dotnet-warp.
幸运的是,休伯特·里巴克(Hubert Rybak )创建了一个非常不错的“ dotnet-warp ”全局工具,将其全部包装到一个命令dotnet-warp中。
All you have to do is this:
您所要做的就是:
C:\supertestweb> dotnet tool install -g dotnet-warp
C:\supertestweb> dotnet-warp
O Running Publish...
O Running Pack...
In this example, I just took a Razor web app with "dotnet new razor" and then packed it up with this tool using Warp packer. Now I've got a 40 meg self-contained app. I don't need to install anything, it just works.
在此示例中,我只是使用了带有“ dotnet new razor”的Razor Web应用程序,然后使用Warp Packer将其与该工具打包在一起。 现在,我有一个40兆的独立应用程序。 我不需要安装任何东西,它可以正常工作。
C:\supertestweb> dir
Directory: C:\supertestweb
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/6/2019 9:14 AM bin
d----- 2/6/2019 9:14 AM obj
d----- 2/6/2019 9:13 AM Pages
d----- 2/6/2019 9:13 AM Properties
d----- 2/6/2019 9:13 AM wwwroot
-a---- 2/6/2019 9:13 AM 146 appsettings.Development.json
-a---- 2/6/2019 9:13 AM 157 appsettings.json
-a---- 2/6/2019 9:13 AM 767 Program.cs
-a---- 2/6/2019 9:13 AM 2115 Startup.cs
-a---- 2/6/2019 9:13 AM 294 supertestweb.csproj
-a---- 2/6/2019 9:15 AM 40982879 supertestweb.exe
Now here's what it gets interesting. Let's say I have a console app. Hello World, packed with Warp, ends up being about 35 megs. But if I use the "dotnet-warp -l aggressive" the tool will add the Mono ILLinker (tree shaker/trimmer) and shake off all the methods that aren't needed. The resulting single executable? Just 9 megs compressed (20 uncompressed).
现在,这里变得有趣了。 假设我有一个控制台应用程序。 充满了Warp的Hello World最终约为35兆。 但是,如果我使用“ dotnet-warp -lgressive ”,该工具将添加Mono ILLinker(树振动器/修剪器),并取消所有不需要的方法。 生成的单个可执行文件? 压缩仅9兆(未压缩20兆)。
C:\squishedapp> dotnet-warp -l aggressive
O Running AddLinkerPackage...
O Running Publish...
O Running Pack...
O Running RemoveLinkerPackage...
C:\squishedapp> dir
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2/6/2019 9:32 AM bin
d----- 2/6/2019 9:32 AM obj
-a---- 2/6/2019 9:31 AM 47 global.json
-a---- 2/6/2019 9:31 AM 193 Program.cs
-a---- 2/6/2019 9:32 AM 178 squishedapp.csproj
-a---- 2/6/2019 9:32 AM 9116643 squishedapp.exe
Here is where you come in!
这就是你进来的地方!
NOTE: The .NET team has planned to have a "single EXE" supported packing solution built into .NET 3.0. There's a lot of ways to do this. Do you zip it all up with a header/unzipper? Well, that would hit the disk a lot and be messy. Do you "unzip" into memory? Do you merge into a single assembly? Or do you try to AoT (Ahead of Time) compile and do as much work as possible before you merge things? Is a small size more important than speed?
注意: .NET团队已计划在.NET 3.0中内置受“单个EXE”支持的打包解决方案。 有很多方法可以做到这一点。 您是否使用标头/解压缩器将其全部拉上拉链? 好吧,这会在磁盘上造成很多麻烦。 您是否“解压缩”到内存中? 您是否合并为单个程序集? 还是在合并之前先尝试AoT(提前)编译并做尽可能多的工作? 小尺寸比速度重要吗?
What do you think? How should a built-in feature like this work and what would YOU focus on?
你怎么看? 这样的内置功能应该如何工作?您将关注什么?
Sponsor: Check out Seq 5 for real-time diagnostics from ASP.NET Core and Serilog, now with faster queries, support for Docker on Linux, and beautiful new dark and light themes.
赞助商:从Seq 5中获取来自ASP.NET Core和Serilog的实时诊断,现在具有更快的查询,对Linux上的Docker的支持以及新的明暗主题。