C# on Visual Studio Code
2016-09-13 11:07
579 查看
installation
Download .NET Core SDK installer and install it.https://www.microsoft.com/net/download
.NET Core SDK = Develop apps with .NET Core and the SDK+CLI (Software Development Kit/Command Line Interface) tools
Install Visual Studio Code
Install Visual Studio Code extensions for C# Development
C# (C# for Visual Studio Code (powered by OmniSharp))
Create a C# project
Create a folder for your .NET application, e.g. NetApp.Open a command windows and go to the folder.
Run
dotnet new
Output:
E:\Work\NetApp>dotnet new Created new C# project in E:\Work\NetApp.
The command will creat a project.json file and a Program.cs file.
Build the project
Open the folder via Visual StudioVisual Studio Code will prompt:
Required assets to build and debug are missing from your project, Add them?
Click Yes
The operation is same as
Create a .vscode folder
Add a launch.json file into the .vscode folder
{ "version": "0.2.0", "configurations": [ { "name": ".NET Core Launch (console)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceRoot}\\bin\\Debug\\netcoreapp1.0\\NetApp.dll", "args": [], "cwd": "${workspaceRoot}", "externalConsole": false, "stopAtEntry": false, "internalConsoleOptions": "openOnSessionStart" }, { "name": ".NET Core Attach", "type": "coreclr", "request": "attach", "processId": "${command.pickProcess}" } ] }
Add a tasks.json file into the .vscode folder
{ "version": "0.1.0", "command": "dotnet", "isShellCommand": true, "args": [], "tasks": [ { "taskName": "build", "args": [ "${workspaceRoot}\\project.json" ], "isBuildCommand": true, "problemMatcher": "$msCompile" } ] }
There are unresolved dependencies from 'project.json', Please execute the restore command to continue.
Click Restore
The operation will create a project.lock.json, which is same as run
dotnet restore
Build
Press Ctrl + Shift + B,
Output:
Project NetApp (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing Compiling NetApp for .NETCoreApp,Version=v1.0 Compilation succeeded. 0 Warning(s) 0 Error(s) Time elapsed 00:00:03.4166048
Run the project
Edit .vscode/task.json{ "version": "0.1.0", "command": "dotnet", "isShellCommand": true, "args": [], "tasks": [ { "taskName": "build", "args": [ "${workspaceRoot}\\project.json" ], "isBuildCommand": true, "problemMatcher": "$msCompile" }, { "taskName": "run", "args": [ "${workspaceRoot}\\project.json" ], "isBuildCommand": false, "problemMatcher": "$msCompile" } ] }
Run the project
Way 1:
Press Ctrl + P
Input "task ", need a space
Select run
Way 2:
Press Ctrl + Shift + P
Input > Tasks: Run Tasks, press enter
Select run
Output:
Project NetApp (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation. Hello World!
Trick: Run the project with Ctrl+Shift+B
Change the .vscode/task.json by
set task build's isBuildCommand as false,
set task run's isBuildCommand as true,
like:
{ "version": "0.1.0", "command": "dotnet", "isShellCommand": true, "args": [], "tasks": [ { "taskName": "build", "args": [ "${workspaceRoot}\\project.json" ], "isBuildCommand": false, "problemMatcher": "$msCompile" }, { "taskName": "run", "args": [ "${workspaceRoot}\\project.json" ], "isBuildCommand": true, "problemMatcher": "$msCompile" } ] }
Try the trick
Press Ctrl+Shift+B
Output:
Project NetApp (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation. Hello World!
Useful User Settings
Auto saveSelect File -> Preferences -> User Settings
// Place your settings in this file to overwrite the default settings { "files.autoSave": "afterDelay" }
相关文章推荐
- Refactoring C# Code Using Visual Studio 2005 ----MSDN
- First ASP.NET Core Application on a Mac Using Visual Studio Code
- 在Visual Studio Code中运行C#项目程序
- CodeRush for Visual Studio .NET v.3.0.1 (Beta) released on 4 Dec 2007
- 剖析并利用Visual Studio Code在Mac上编译、调试c#程序
- 剖析并利用Visual Studio Code在Mac上编译、调试c#程序
- 剖析并利用Visual Studio Code在Mac上编译、调试c#程序【转】
- [乐意黎原创]Node.js 出现Error:Cannot find runtime 'node' on PATH - Visual Studio Code中的解决办法
- How to debug .NET Core RC2 app with Visual Studio Code on Windows?
- CodeRush for Visual Studio .NET v.3.0.1 (Beta) released on 4 Dec 2007
- Why do I keep getting mixed tabs and spaces in a Visual Studio C# code window?[vs power tools issue transfered]
- Safe! Repel Attacks on Your Code with the Visual Studio 2005 Safe C and C++ Libraries
- Apache Cordova development lands on Visual Studio Code
- 在Visual Studio Code中使用C#以及.net core
- How To Install Visual Studio Code On Ubuntu
- Visual Studio Code创建C#项目
- 剖析并利用Visual Studio Code在Mac上编译、调试c#程序 集成到Unity3D
- Getting started with aspnet5 and visualstudio code on a mac or linux
- Refactoring C# Code Using Visual Studio 2005