[.NET Core] Publish 一個 ASP.NET Core 應用程式

接續上一篇已經創建好一個ASP.NET Core的專案,這篇要來教如何 Publish,有了這一步才能將其部屬到其他平台上運作。

(環境:Windows 10, Visual Studio Enterprise 2019(16.7.2), .Net Core 3.1)
  1. 開啟 cmd 進到專案的資料夾裡
    C:\>cd C:\Users\wrxue\source\repos\CorePractice
    
  2. 使用 Release 組建組態並以指令 publish,下方紅色資訊為該專案 publish 出來的資料夾位置
    C:\Users\wrxue\source\repos\CorePractice>dotnet publish -c Release
    Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET
    Copyright (C) Microsoft Corporation. All rights reserved.
    
      Determining projects to restore...
      All projects are up-to-date for restore.
      CorePractice -> C:\Users\wrxue\source\repos\CorePractice\CorePractice\bin\Release\netcoreapp3.1\CorePractice.dll
      CorePractice -> C:\Users\wrxue\source\repos\CorePractice\CorePractice\bin\Release\netcoreapp3.1\CorePractice.Views.dll
      CorePractice -> C:\Users\wrxue\source\repos\CorePractice\CorePractice\bin\Release\netcoreapp3.1\publish\
    
  3. 開啟 publish 內的應用程式,此時應用程式在「http://localhost:5000」監聽囉,開啟瀏灠器輸入即可連線
    C:\Users\wrxue\source\repos\CorePractice\CorePractice\bin\Release\netcoreapp3.1\publish>dotnet CorePractice.dll #這裡是dll,不是exe
    info: Microsoft.Hosting.Lifetime[0]
          Now listening on: http://localhost:5000
    info: Microsoft.Hosting.Lifetime[0]
          Now listening on: https://localhost:5001
    info: Microsoft.Hosting.Lifetime[0]
          Application started. Press Ctrl+C to shut down.
    info: Microsoft.Hosting.Lifetime[0]
          Hosting environment: Production
    info: Microsoft.Hosting.Lifetime[0]
          Content root path: C:\Users\wrxue\source\repos\CorePractice\CorePractice\bin\Release\netcoreapp3.1\publish
    
    (注意:根目錄為執行指令「dotnet CorePractice.dll」時的目錄)

留言

這個網誌中的熱門文章

[Hyper-V] 讓 Windows 可以吃到超過 16TB 的硬碟!