使用 Visual Studio for Mac 在 macOS 上開始使用 .NET CoreGet started with .NET Core on macOS using Visual Studio for Mac

Visual Studio for Mac 針對開發 .NET Core 應用程式,提供功能完整的整合式開發環境 (IDE)。Visual Studio for Mac provides a full-featured Integrated Development Environment (IDE) for developing .NET Core applications. 本主題會逐步引導您使用 Visual Studio for Mac 和 .NET Core 建置簡單主控台應用程式。This topic walks you through building a simple console application using Visual Studio for Mac and .NET Core.

注意

我們非常重視您的意見反應。Your feedback is highly valued. 您有兩種方式可以提供意見反應給 Visual Studio for Mac 開發小組:There are two ways you can provide feedback to the development team on Visual Studio for Mac:

  • 在 Visual Studio for Mac 中,從功能表選取 [說明] > [回報問題] ,或從歡迎畫面選取 [回報問題] ,這會開啟用來提出錯誤報告的視窗。In Visual Studio for Mac, select Help > Report a Problem from the menu or Report a Problem from the Welcome screen, which will open a window for filing a bug report. 您可在開發人員社群入口網站追蹤您的意見反應。You can track your feedback in the Developer Community portal.
  • 若要提出建議,請從功能表選取 [說明] > [提供建議] ,或從歡迎畫面選取 [提供建議] ,這會帶您前往 Visual Studio for Mac 開發人員社群網頁 (英文)。To make a suggestion, select Help > Provide a Suggestion from the menu or Provide a Suggestion from the Welcome screen, which will take you to the Visual Studio for Mac Developer Community webpage.

必要條件Prerequisites

請參閱 Mac 上 .NET Core 的先決條件主題。See the Prerequisites for .NET Core on Mac topic.

開始使用Get started

如果您已經安裝必要條件和 Visual Studio for Mac,請略過本節並移至建立專案If you've already installed the prerequisites and Visual Studio for Mac, skip this section and proceed to Creating a project. 請遵循下列步驟來安裝必要條件和 Visual Studio for Mac:Follow these steps to install the prerequisites and Visual Studio for Mac:

下載 Visual Studio for Mac 安裝程式Download the Visual Studio for Mac installer. 執行安裝程式。Run the installer. 閱讀並接受授權合約。Read and accept the license agreement. 安裝過程中,系統會詢問您是否要安裝 Xamarin,這是一個跨平台的行動應用程式開發技術。During the install, you're provided the opportunity to install Xamarin, a cross-platform mobile app development technology. 針對 .NET Core 開發,安裝 Xamarin 和其相關元件為選擇性。Installing Xamarin and its related components is optional for .NET Core development. 如需 Visual Studio for Mac 安裝程序的逐步解說,請參閱 Visual Studio for Mac 文件For a walk-through of the Visual Studio for Mac install process, see Visual Studio for Mac documentation. 安裝完成後,請啟動 Visual Studio for Mac IDE。When the install is complete, start the Visual Studio for Mac IDE.

建立專案Creating a project

  1. 選取歡迎畫面上的 [新增專案] 。Select New Project on the Welcome screen.

    Visual Studio for Mac 歡迎畫面上的 [新增專案] 按鈕

  2. 在 [新增專案] 對話方塊中,選取 [.NET Core] 節點下的 [應用程式] 。In the New Project dialog, select App under the .NET Core node. 選取 [主控台應用程式] 範本,接著選取 [下一步] 。Select the Console Application template followed by Next.

    [新增專案] 範本清單

  3. 針對 [專案名稱] 輸入 "HelloWorld"。Type "HelloWorld" for the Project Name. 選取 [建立] 。Select Create.

    設定新主控台應用程式對話方塊

  4. 等候專案的相依性還原完畢。Wait while the project's dependencies are restored. 專案具有單一 C# 檔案 Program.cs,其中包含具有 Main 方法的 Program 類別。The project has a single C# file, Program.cs, containing a Program class with a Main method. 執行應用程式時,Console.WriteLine 陳述式會將 "Hello World!"The Console.WriteLine statement will output "Hello World!" 輸出到主控台。to the console when the app is run.

    開啟 Program.cs 檔案的主視窗

執行應用程式Run the application

使用 F5 以偵錯模式執行應用程式,或使用 CTRL+F5 以發行模式執行應用程式。Run the app in Debug mode using F5 or in Release mode using CTRL+F5.

[應用程式輸出] 窗格顯示 Hello World!

後續步驟Next step

使用 Visual Studio for Mac 在 macOS 上建置完整的 .NET Core 解決方案主題,能說明如何建置一個包含可重複使用之程式庫和單元測試的完整 .NET Core 解決方案。The Building a complete .NET Core solution on macOS using Visual Studio for Mac topic shows you how to build a complete .NET Core solution that includes a reusable library and unit testing.