在 Visual Studio for Mac 中編譯和建置Compiling and building in Visual Studio for Mac

Visual Studio for Mac 可用來在專案開發期間建置應用程式和建立組件。Visual Studio for Mac can be used to build applications and create assemblies during the development of your project. 頻繁地建置您的程式碼以允許快速識別類型不符、易發生錯誤的語法、拼錯的關鍵字與其他編譯時間錯誤非常重要。It's important to build your code often to allow you to quickly identify type mismatches, erroneous syntax, misspelled keywords, and other compile-time errors. 透過建置並偵錯,您也可以尋找並修正執行階段錯誤,例如邏輯、IO 與除以零錯誤。By building then debugging, you can also find and fix run-time errors such as logic, IO, and divide-by-zero errors.

成功的建置表示原始程式碼包含正確的語法,而且對程式庫、組件與其他元件的所有靜態參考都能成功解析。A successful build means the source code contains correct syntax and all static references to libraries, assemblies, and other components can resolve. 建置程序會產生應用程式可執行檔。The build process produces an application executable. 這個可執行檔接著可透過偵錯與其他類型的手動與自動測試來驗證程式碼品質。This executable may then be tested via debugging and different kinds of manual and automated tests to validate code quality. 完整測試您的應用程式之後,您便能編譯發行版本以部署到您的客戶。After your application is fully tested, you can compile a release version to deploy to your customers.

在 Mac 上,您可以使用下列任何一種方法來建立您的應用程式: Visual Studio for Mac、MSBuild 命令列工具或 Azure Pipelines。On the Mac, you can use any of the following methods to build your application: Visual Studio for Mac, MSBuild command-line tools, or Azure Pipelines.

建置方法Build Method 優點Benefits
Visual Studio for MacVisual Studio for Mac - 立即建立組建並在偵錯工具中加以測試。- Create builds immediately and test them in a debugger.
- 對 C# 專案執行多處理器組建。- Run multi-processor builds for C# projects.
- 自訂建置系統的不同層面。- Customize different aspects of the build system.
MSBuild 命令列MSBuild command line - 無須安裝 Visual Studio for Mac 即可建置專案。- Build projects without installing Visual Studio for Mac.
- 對所有專案類型執行多處理器建置。- Run multi-processor builds for all project types.
- 自訂建置系統大部分的區域。- Customize most areas of the build system.
Azure PipelinesAzure Pipelines - 將建置流程自動化,這是持續整合/持續傳遞管線的一部分。- Automate your build process as part of a continuous integration/continuous delivery pipeline.
- 在每個組建套用自動化的測試。- Apply automated tests with every build.
- 在建置流程採用幾乎不受限制的雲端式資源。- Employ virtually unlimited cloud-based resources for build processes.
- 修改建置工作流程,以及建立建置活動以執行深入自訂的工作。- Modify the build workflow and create build activities to perform deeply customized tasks.

本節文件進一步說明使用 IDE 的建置流程詳細資料。The documentation in this section goes into further details of the IDE-based build process. 如需有關透過命列列建置應用程式的詳細資訊,請參閱 MSBuildFor more information about building applications via the command line, see MSBuild. 如需有關使用 Azure Pipelines 來建置應用程式的詳細資訊,請參閱 Azure PipelinesFor details on building applications with Azure Pipelines, see Azure Pipelines.

注意

本主題適用於 Visual Studio for Mac。This topic applies to Visual Studio for Mac. 針對 Windows 上的 Visual Studio,請參閱在 Visual Studio 中編譯與建置For Visual Studio on Windows, see Compile and build in Visual Studio.

從 IDE 建置Building from the IDE

Visual Studio for Mac 可讓您立即建立和執行組建,同時仍然能夠控制組建功能。Visual Studio for Mac lets you create and run builds instantly, while still giving you control over build functionality. 當您建立專案時,Visual Studio for Mac 會定義預設建置設定 (這會設定建置的上下文)。When you create a project, Visual Studio for Mac defines a default build configuration that sets the context for builds. 您可以編輯預設建置設定,而且也可以建立您自己的建置設定。You can edit default build configurations and also create your own. 建立或修改這些組態會自動更新專案檔,MSBuild 之後會使用該檔案來建置專案。Creating or modifying these configurations will automatically update the project file, which is then used by MSBuild to build your project.

如需如何在 IDE 中建立專案和方案的詳細資訊,請參閱建置和清除專案與方案指南。For more information regarding how to build projects and solutions in the IDE, see the Building and cleaning Projects and Solutions guide.

Visual Studio for Mac 也可用來執行下列作業:Visual Studio for Mac can also be used to do the following:

  • 變更輸出路徑。Change the output path. 這是在您的專案選項中進行編輯:This is edited in your Project's options:

    變更輸出路徑

  • 變更組建輸出的詳細資訊:Change the verbosity of the build output:

    變更組建的詳細資訊

  • 在建置或清除之前、期間或之後加入自訂命令:Add Custom Commands before, during, or after Building or Cleaning:

    新增自訂命令

另請參閱See also