欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

dotnet core瘦身发布

程序员文章站 2022-04-28 21:57:11
需要安装nuget包Microsoft.Packaging.Tools.Trimming然后利用如下命令发布dotnet publish -r win10-x64 -c release --self-contained true /p:TrimUnusedDependencies=true发布完成之 ......

需要安装nuget包microsoft.packaging.tools.trimming
然后利用如下命令发布
dotnet publish -r win10-x64 -c release --self-contained true /p:trimunuseddependencies=true
发布完成之后,实际上还是有不少dll文件,只不过由原来的200多个减少了70多个。
 
然后还有个瘦身的方法
项目地址
国内这毛线网可能有点慢

关于windows摘录如下

windows

create a simple console application

ps c:\users\diego\devel> mkdir myappps c:\users\diego\devel> cd myappps c:\users\diego\devel\myapp> dotnet new consoleps c:\users\diego\devel\myapp> dotnet runhello world!ps c:\users\diego\devel\myapp>

publish the application with native installer for win10-x64 runtime

ps c:\users\diego\devel\myapp> dotnet publish -c release -r win10-x64

the application should be published to bin/release/netcoreapp2.1/win10-x64/publish/

download warp-packer

if you save warp-packer in a directory in your path, you only need to download it once.

ps c:\users\diego\devel\myapp> [net.servicepointmanager]::securityprotocol = "tls12, tls11, tls" ; invoke-webrequest https://github.com/dgiagio/warp/releases/download/v0.3.0/windows-x64.warp-packer.exe -outfile warp-packer.exe

create your self-contained application

ps c:\users\diego\devel\myapp> .\warp-packer --arch windows-x64 --input_dir bin/release/netcoreapp2.1/win10-x64/publish --exec myapp.exe --output myapp.exe

run your self-contained application

ps c:\users\diego\devel\myapp> .\myapp.exehello world!ps c:\users\diego\devel\myapp>

more information about your self-contained application

ps c:\users\diego\devel\myapp> "{0:n2} mb" -f ((get-item myapp.exe).length / 1mb)28.51 mb


坑爹的情况是,这个warp程序会一直下载不下来,然后尝试文档中提到的用power shell下载
在powsershell 中执行如下语句
[net.servicepointmanager]::securityprotocol = "tls12, tls11, tls" ; invoke-webrequest https://github.com/dgiagio/warp/releases/download/v0.3.0/windows-x64.warp-packer.exe -outfile warp-packer.exe
孬好速度比浏览器要一点,下载完后,准备打包

按照指令格式,拼装指令,示例如下,然后就可以将exe和dll打包成1个exe了

ps e:\dijingtools\dijing.update> .\warp-packer.exe --arch windows-x64 --exec dijing.update.exe --input_dir
.\bin\release\netcoreapp2.1\win10-x64\publish\ --output dijing.update.exe


然后测试一下exe,可以正常,这样部署的时候,就不用带很多程序了

ps e:\dijingtools\dijing.update\bin\debug\netcoreapp2.1\publish> .\dijing.update.exe 
ges/106sp7fc10b15-8dd8-4ecc-ba02-f52a833b3783.zip
文件夹e:\dijingtools\dijing.update\bin\debug\netcoreapp2.1\publish\temp创建成功
升级包开始下载
升级包下载中...3833,157757,2%
升级包下载中...13587,157757,8%
升级包下载中...46063,157757,29%
升级包下载中...71479,157757,45%
升级包下载中...137015,157757,86%
升级包下载中...140667,157757,89%
升级包下载中...157757,157757,100%
升级包下载完成
检测到升级包已存在
升级包解压完成
升级文件遍历完成,文件个数为:5
升级包文件覆盖完成
临时文件夹删除完成

程序启动成功 
ps e:\dijingtools\dijing.update\bin\debug\netcoreapp2.1\publish> 



还有一种corelr的东西,也可以瘦身,不过注入关系得自己写个表,就懒得弄了