Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
permalink display title tags emotag date comment layout component
/posts/dotnet-publish-single-file
normal
dotnet生成单一exe文件
C#
2019-11-25 01:50:43 UTC
true
post

以下以dotnet core 3.0为准。

  • 需要安装dotnet运行时,但编译结果很小

dotnet publish -c Release -r win-x64 -o publish /p:PublishSingleFile=true --no-self-contained

  • 无需运行时,编译结果会变大

dotnet publish -c Release -r win-x64 -o publish /p:PublishSingleFile=true /p:PublishTrimmed=true /p:PublishReadyToRun=true

说明:PublishTrimmed会对用不到的库作精简,PublishReadyToRun会增加native code以加速启动。

由于每个项目的特点不同,这些命令可能会造成运行错误,需要自行测试。

常见的runtime选项win-x64, win-x86, win-arm, linux-x64, linux-arm