内容简介:我之前曾經在由於
我之前曾經在 如何將 SCD 部署的 .NET Core 應用程式封裝單一可執行檔 (Warp) 文章中分享過 Warp 這套工具,也在該文最後分享 CoreRT 應該才是最終的解決方案。今天這篇文章我就來分享如何透過 CoreRT 來編譯你的 .NET Core 應用程式!
建立 .NET Core 主控台應用程式
-
先限定 .NET CLI 使用版本
dotnet new globaljson --sdk-version 2.2.101
-
建立專案
dotnet new console -n c1 cd c1
設定 dotnet-core 套件來源
由於 CoreRT 目前還在 Alpha 階段,所有尚在開發、測試中的 .NET Core 工具、套件,預設都不會上架到 NuGet Gallery ,而是放在 dotnet-core 這裡。
-
建立 nuget.config 設定檔
我們必須先建立一個
nuget.config設定檔,方便我們對專案設定 NuGet 套件來源。dotnet new nuget
-
新增
dotnet-core套件來源加入 dotnet-core 套件來源到
nuget.config之中。nuget sources add -Name dotnet-core -Source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json
建立完成後的 nuget.config 內容如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
</packageSources>
</configuration>
新增 Microsoft.DotNet.ILCompiler 套件
以下命令會自動安裝 1.0.0-alpha-* 最新版本:
dotnet add package Microsoft.DotNet.ILCompiler -v 1.0.0-alpha-*
直接透過 .NET CLI 的 SCD 進行建置
這時我們就可以好好比對一下目前 .NET Core SCD 與 CoreRT SCD 的差異之處!
-
使用 CoreRT 發行
dotnet publish -r win-x64 -c Release -o dist-corert
總建置大小約為
15MB左右,檔案數量為4個,而且啟動速度超快! -
使用傳統 .NET Core SCD 發行
我們只要移除 Microsoft.DotNet.ILCompiler 套件,就可以切回目前的編譯方式。
dotnet remove package Microsoft.DotNet.ILCompiler dotnet publish -r win-x64 -c Release -o dist-netcore
總建置大小約為
66.1MB左右,檔案數量為217個。
數字可以證明一切, CoreRT 就是未來的明日之星,完全可以期待它的到來!
本篇文章的命令整理
dotnet new globaljson --sdk-version 2.2.101 dotnet new console -n c1 cd c1 dotnet new nuget nuget sources add -Name dotnet-core -Source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json dotnet add package Microsoft.DotNet.ILCompiler -v 1.0.0-alpha-* dotnet publish -r win-x64 -c Release -o dist-corert dotnet remove package Microsoft.DotNet.ILCompiler dotnet publish -r win-x64 -c Release -o dist-netcore
相關連結
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Programming Collective Intelligence
Toby Segaran / O'Reilly Media / 2007-8-26 / USD 39.99
Want to tap the power behind search rankings, product recommendations, social bookmarking, and online matchmaking? This fascinating book demonstrates how you can build Web 2.0 applications to mine the......一起来看看 《Programming Collective Intelligence》 这本书的介绍吧!