使用VS Code開發 調試.NET Core 應用程序
使用VS Code開發 調試.NET Core RC2應用程序,由於.NET Core 目前還處於預覽版。
本文使用微軟提供的示例進行開發及調試。
https://github.com/aspnet/cli-samples
.NET Core 介紹及說明:
https://github.com/dotnet/cli
http://dotnet.github.io/getting-started/
環境安裝
本文開發的實際環境: win10 x64 VSCode 1.0
下載
https://github.com/dotnet/cli#installers-and-binaries
.NET Core SDK Installer:
https://dotnetcli.blob.core.windows.net/dotnet/beta/Installers/Latest/dotnet-dev-win-x64.latest.exe
VSCode :
https://code.visualstudio.com/
VSCode C#插件:
https://github.com/OmniSharp/omnisharp-vscode/releases
最新版: https://github.com/OmniSharp/omnisharp-vscode/releases/download/v1.0.4-rc2/csharp-1.0.4-rc2.vsix
安裝好VSCode以后,打開VSCode 安裝C#插件。
安裝插件:直接用VSCode 打開插件文件就可以安裝了。
安裝好以后 F1 會發現多了dotnet 命令,證明也就安裝完成。
開發調試
下載微軟的示例代碼:https://github.com/aspnet/cli-samples
下載代碼后,使用VSCode 打開文件夾 cli-samples/HelloMvc
F1 輸入 dotnet restore
選擇對應的dotnet restor (這里顯示好像是插件的bug)
你還可以直接在文件夾打開命令行,輸入 dotnet restore 同樣可以還原相關引用。
還原好相關的引用以后我們就可以進行調試了。
點擊調試 程序就跑起來。
這樣就可以下斷點調試。
訪問 http://localhost:5000/
開發
我們來添加一個新的Action
[HttpGet("/about")] public IActionResult About(){ var useragent=Request.Headers["User-Agent"]; return Content(useragent+"\r\nabout by linezero"); }
訪問: http://localhost:5000/about
下斷點調試一下程序,斷點設置跟VS一樣。
斷下來以后,可以查看對應的屬性以及值。
左側有對應的監視器,可以查看各個值。
這樣我們已經可以調試.NET Core。
如果你覺得本文對你有幫助,請點擊“推薦”,謝謝。