使用 Visual Studio for Mac 發行至資料夾Publish to a folder using Visual Studio for Mac

您可以使用 [發佈] 工具,將 .NET Core 主控台或 ASP.NET Core 應用程式發佈到資料夾。You can use the Publish tool to publish .NET Core Console or ASP.NET Core apps to a folder.

先決條件Prerequisites

發佈到資料夾Publish to Folder

使用 Visual Studio for Mac 您可以使用 [發行] 工具,將您的 .NET Core 專案發行到資料夾。Using Visual Studio for Mac you can publish your .NET Core projects to a folder using the Publish tool. 發行到資料夾之後,您可以將檔案傳送到不同的環境。After publishing to a folder you can transfer the files to a different environment. 若要發佈到資料夾,請執行下列步驟。To publish to a folder follow these steps.

  1. 在 [方案] 視窗中,以滑鼠右鍵按一下專案,然後選擇 [ 發行 ]。In the Solution Window, right-click the project and choose Publish.

    [發佈] 操作功能表

  2. 如果您之前已發佈此專案,您將會在功能表中看到發行設定檔。If you have previously published this project, you'll see the publish profile in the menu. 選取該發行設定檔即可啟動發佈程序。Select that publish profile to start the publish process.

  3. 若是第一次將此專案發佈到資料夾,請選取 [發佈到資料夾]To publish this project to a folder for the first time, select Publish to Folder

    [發佈到資料夾] 操作功能表

  4. [發佈到資料夾] 對話方塊會隨即出現。The Publish to Folder dialog appears. 在此對話方塊中,您可以自訂要發佈專案的資料夾。On this dialog you can customize the folder where the project will be published. 您可以使用 [瀏覽] 按鈕來執行這項作業,或貼至路徑。You can use the Browse button to do this, or paste in a path.

  5. 按一下 [發佈] 之後,會發生幾件事。After clicking Publish a few things happen. 首先會建立發行設定檔。First a publish profile is created. 發行設定檔是發佈程序期間匯入專案的 MSBuild 檔。A publish profile is an MSBuild file that is imported into the project during the publish process. 其中包含發佈程序期間所使用的屬性。It contains the properties that are used during the publish process. 這些檔案會儲存在 Properties/PublishProfiles 中並具有副檔名 .pubxmlThese files are stored in the Properties/PublishProfiles and have the extension .pubxml. 接著會啟動發佈程序。Next, the publish process is started. 您可以在 Visual Studio for Mac 中監看狀態列來監視進度。You can monitor the progress by watching the status bar in Visual Studio for Mac.

    具有發佈狀態的 IDE 狀態列

  6. 一旦發佈成功完成,[搜尋工具] 視窗就會開啟至發佈資料夾。Once publish completes successfully a Finder window will open to the publish folder. 現在已建立發行設定檔,它會顯示在 [發佈] 操作功能表中。Now that a publish profile has been created, it will be displayed in the Publish context menu.

    具有資料夾設定檔的 [發佈] 操作功能表

  7. 若要使用相同的設定再次發佈專案,您可以按一下 [發佈] 操作功能表中的設定檔。To publish the project again with the same settings you can click on the profile in the publish context menu.

自訂發佈選項Customize Publish Options

若要變更發行設定檔的名稱 (這會顯示在 [發佈] 操作功能表中),請重新命名發行設定檔。To change the name of the publish profile (which is displayed in the publish context menu), rename the publish profile file. 請勿變更檔案的副檔名 (.pubxml)。Make sure to not change the extension of the file (.pubxml).

若要變更發佈資料夾路徑,請開啟發行設定檔並編輯 publishUrl 值。To change the publish folder path, open the publish profile and edit the publishUrl value.

若要變更使用的組建組態,請變更發行設定檔中的 LastUsedBuildConfiguration 屬性。To change the build configuration that is used, change the LastUsedBuildConfiguration property in the publish profile.