[轉]netcore發佈獨立單文件(非託管dll也打包進程序裏)

命令行模板

dotnet publish -r <運行時> -c Release -f <框架版本,單框架時可不指定> --self-contained -p:PublishSingleFile=<單文件 true/false> -p:PublishTrimmed=<裁剪 true/false> (-p:IncludeNativeLibrariesForSelfExtract=<原生庫以自解壓形式打包 true/false> 或 -p:IncludeAllContentForSelfExtract=<全部內容文件以自解壓形式打包 true/false>)

例子

dotnet publish -r win-x64 -c Release -f net6.0 --self-contained -p:PublishSingleFile=true -p:PublishTrimmed=true -p:IncludeNativeLibrariesForSelfExtract=true
dotnet publish -r linux-x64 -c Release --self-contained -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true

注意

如果不使用IncludeNativeLibrariesForSelfExtract參數,打包出來的單文件會同時輸出native dll作爲依賴,不算真正的單文件,使用IncludeNativeLibrariesForSelfExtract後把native dll作爲自解壓打包進去,纔是真正的“單”文件。
如果有其他內容文件,要使用IncludeAllContentForSelfExtract,會把全部內容文件也打包進去。
運行程序時,會先把原生庫自動解壓到C:\Users\用戶名\AppData\Local\Temp\.net\程序文件名\下的一個文件夾中。

使用PublishTrimmed時,要檢查生成的文件運行是否正常,以防必要的依賴被裁剪掉。

 

轉自: https://www.cnblogs.com/zonciu/p/13961051.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章