1. 程式人生 > >在mac上使用VS Code編寫C#應用程式

在mac上使用VS Code編寫C#應用程式

Visual Studio Code是微軟的跨平臺的VS開發工具,依賴於dot net core的跨平臺功能。

首先需要在mac上安裝dot net core 開發包(包含dot net core 執行時),dot net core mac 版 官方網站:

https://www.microsoft.com/net/core#macos

下載並安裝

這個地址是關於各種安裝異常的問題的方案

https://github.com/dotnet/core/blob/master/cli/known-issues.md

我這邊就出現了一個問題,安裝完成之後,在終端執行 dotnet命令,提示Command not found。

這個問題可以執行這個命令解決:

ln -s /usr/local/share/dotnet/dotnet /usr/local/bin

然後又出現了dotnew new 命令異常的問題,原因是新安裝的openssl沒有替換掉系統自帶的版本。

在終端執行這個命令可以解決:

sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib

不過要將1.0.0替換為當前安裝的dotnet core版本。我這裡需要替換為1.0.1

安裝完成之後,開啟終端,可以測試一下。

進入一個資料夾,執行一下命令:

dotnet  new

dotnet restore

dotnet run

如果打印出了

Hello World!

則一切正常。

下載並安裝Visual Studio Core

https://code.visualstudio.com/c?utm_expid=101350005-28.R1T8FshdTBWEfZjY0s7XKQ.2&utm_referrer=https%3A%2F%2Fcode.visualstudio.com%2Fdocs%2Fsetup%2Fmac

在 mac上的專案檔案都是以資料夾或者project.json檔案定義的,所有沒有新建專案之類的選單可用。


為VS Core 安裝 C# Extension 外掛

開啟VS Core 的命令面板,輸入 ext install C# 命令來出發安裝C#外掛請求。

C# Extension外掛安裝完成之後,現在可以建立並除錯專案了

在資源管理器中右鍵,開啟終端,執行命令 建立專案

dotnet new

dotnet restore


開啟除錯面板,除錯目標選擇 .Net Core Launch(Console)

點選除錯按鈕,提示需要配置除錯資訊.

在launch.json檔案中,編輯Program引數來設定要除錯的dll的路徑。

現在可以開始除錯。

附:外國妹子的初級指引視訊

https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-using-CSharp-and-NET-Core