半年前(2月20日)测试过,现在(2021年8月25日)再次使用最新的 .NET 6.0.0-preview.7 再次验证一下。
PS C:\Users\Administrator> dotnet --version 6.0.100-preview.7.21379.14
直接新建了一个默认项目:
PS D:\Project\net6> dotnet new console The template "Console Application" was created successfully. Processing post-creation actions... Running 'dotnet restore' on D:\Project\net6\net6.csproj... 正在确定要还原的项目… 已还原 D:\Project\net6\net6.csproj (用时 75 ms)。 Restore succeeded.
默认单文件,一个Hello World! 60MB 60.2MB:
PS D:\Project\net6> dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained true 用于 .NET 的 Microsoft (R) 生成引擎版本 16.9.0-preview-21103-02+198f3f262 版权所有(C) Microsoft Corporation。保留所有权利。 正在确定要还原的项目… 所有项目均是最新的,无法还原。 你正在使用 .NET 的预览版。请查看 https://aka.ms/dotnet-core-preview net6 -> D:\Project\net6\bin\Debug\net6.0\win-x64\net6.dll net6 -> D:\Project\net6\bin\Debug\net6.0\win-x64\publish\ PS C:\Users\Administrator> D:\Project\net6\bin\Debug\net6.0\win-x64\publish\net6.exe Hello World! PS D:\Project\net6> dir .\bin\Debug\net6.0\win-x64\publish\ 目录: D:\Project\net6\bin\Debug\net6.0\win-x64\publish Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2021/2/3 星期三 4:11 mscordaccore.dll -a---- 2021/2/20 星期六 11:09 net6.exe -a---- 2021/2/20 星期六 11:05 9404 net6.pdb
使用PublishTrimmed和PublishReadyToRun参数后 21MB 13.6MB。
PS D:\Project\net6> dotnet publish -r win-x64 -p:PublishSingleFile=true -p:PublishTrimmed=true -p:PublishReadyToRun=true --self-contained true 用于 .NET 的 Microsoft (R) 生成引擎版本 16.9.0-preview-21103-02+198f3f262 版权所有(C) Microsoft Corporation。保留所有权利。 正在确定要还原的项目… 所有项目均是最新的,无法还原。 你正在使用 .NET 的预览版。请查看 https://aka.ms/dotnet-core-preview net6 -> D:\Project\net6\bin\Debug\net6.0\win-x64\net6.dll 正在优化程序集的大小,这可能更改应用的行为。请务必在发布后进行测试。请参阅: https://aka.ms/dotnet-illink net6 -> D:\Project\net6\bin\Debug\net6.0\win-x64\publish\ PS D:\Project\net6> D:\Project\net6\bin\Debug\net6.0\win-x64\publish\net6.exe Hello World! PS D:\Project\net6> dir .\bin\Debug\net6.0\win-x64\publish\ 目录: D:\Project\net6\bin\Debug\net6.0\win-x64\publish Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2021/2/3 星期三 4:11 mscordaccore.dll -a---- 2021/2/20 星期六 11:18 net6.exe -a---- 2021/2/20 星期六 11:05 9404 net6.pdb
只使用PublishTrimmed参数,20MB 10.8MB。
PS D:\Project\net6> dotnet publish -r win-x64 -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true 用于 .NET 的 Microsoft (R) 生成引擎版本 16.9.0-preview-21103-02+198f3f262 版权所有(C) Microsoft Corporation。保留所有权利。 正在确定要还原的项目… 所有项目均是最新的,无法还原。 你正在使用 .NET 的预览版。请查看 https://aka.ms/dotnet-core-preview net6 -> D:\Project\net6\bin\Debug\net6.0\win-x64\net6.dll 正在优化程序集的大小,这可能更改应用的行为。请务必在发布后进行测试。请参阅: https://aka.ms/dotnet-illink net6 -> D:\Project\net6\bin\Debug\net6.0\win-x64\publish\ PS D:\Project\net6> dir .\bin\Debug\net6.0\win-x64\publish\ 目录: D:\Project\net6\bin\Debug\net6.0\win-x64\publish Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2021/2/3 星期三 4:11 mscordaccore.dll -a---- 2021/2/20 星期六 11:22 net6.exe -a---- 2021/2/20 星期六 11:05 9404 net6.pdb PS D:\Project\net6> D:\Project\net6\bin\Debug\net6.0\win-x64\publish\net6.exe Hello World! PS D:\Project\net6>
最后:.NET6的重点当然不是 单文件与go已经没啥差别了。PublishSingleFile,如果是小工具还是go有优势。
参考:https://docs.microsoft.com/zh-cn/dotnet/core/deploying/single-file
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/226553.html原文链接:https://javaforall.net
