C# on Visual Studio Code
[comment]: # C# on Visual Studio Code
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 Studio
 Visual 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
 
 
- Required assets to build and debug are missing from your project, Add them?
{
    "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
 
- There are unresolved dependencies from 'project.json', Please execute the restore command to continue.
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:
 
- Way 1:
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 save
 Select File -> Preferences -> User Settings
// Place your settings in this file to overwrite the default settings
{
    "files.autoSave": "afterDelay"
}
C# on Visual Studio Code的更多相关文章
- Visual Studio Code 代理设置
		Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ... 
- 在Visual Studio Code中配置GO开发环境
		一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ... 
- Visual Studio Code——Angular2 Hello World 之 2.0
		最近看到一篇用Visual Studio Code开发Angular2的文章,也是一篇入门教程,地址为:使用Visual Studio Code開發Angular 2專案.这里按部就班的做了一遍,感觉 ... 
- docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用
		.net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ... 
- Visual Studio Code v0.9.1 发布
		微软的跨平台编辑器 Visual Studio Code v0.9.1 已经发布,官方博客上发布文章Visual Studio Code – October Update (0.9.1):http:/ ... 
- 微软Visual Studio Code 0.8.0发布,新增多种主题
		月30日,Build 开发者大会上,正式宣布了 Visual Studio Code 项目;并将其定义为:一个运行于 Mac OS X.Windows和 Linux 之上的,针对于编写现代 Web 和 ... 
- Visual Studio Code 配置指南
		Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器.在我看来它是「一款完美的编辑器」. 本文是有关 VS Code 的特性介绍与配置指 ... 
- Visual Studio Code,完美的编辑器
		今日凌晨,微软的文本(代码)编辑器 Visual Studio Code(简称 VS Code),发布了首个正式版,距离首个 beta 版上线时间刚好一年. 在十多年的编程经历中,我使用过非常多的的代 ... 
- 打造TypeScript的Visual Studio Code开发环境
		打造TypeScript的Visual Studio Code开发环境 本文转自:https://zhuanlan.zhihu.com/p/21611724 作者: 2gua TypeScript是由 ... 
- Visual Studio Code 使用Git进行版本控制
		Visual Studio Code 使用Git进行版本控制 本来认为此类教程,肯定是满网飞了.今天首次使用VS Code的Git功能,翻遍了 所有中文教程,竟没有一个靠谱的.遂动笔写一篇. 请确保你 ... 
随机推荐
- makeimg
			>./simg2img [system.img] [system2.img]>mount -o loop [system2.img] [s/]>./make_ext4fs -s -l ... 
- mongodb存储过程
			MongoDB支持存储过程的使用,它的存储过程是用javascript实现的,被存在于system.js表中,可以接收和输出参数,返回执行存储过程的状态值,也可以嵌套调用. 所以我理解的Mon ... 
- 并行编程多线程之Parallel
			1.简介 随着多核时代的到来,并行开发越来越展示出它的强大威力!使用并行程序,充分的利用系统资源,提高程序的性能.在.net 4.0中,微软给我们提供了一个新的命名空间:System.Threadin ... 
- python 跳出嵌套循环方法
			class LoopError(Exception):pass rs = '' try: for i in range(1, 3): print i rs = 'one ' if i == 1: fo ... 
- npm 发布包
			每个包都必须包含package.json配置文件 生成package.page文件 1.到项目目录下执行npm init根据提示输入即可 最后记得要yes 完成项目后就是要发布到npm了 首先需要有n ... 
- 细数Qt开发的各种坑(欢迎围观)
			1:Qt的版本多到你数都数不清,多到你开始怀疑人生.从4.6开始到5.8,从MSVC编译器到MINGW编译器,从32位到64位,从Windows到Linux到MAC.MSVC版本还必须安装对应的VS2 ... 
- IIS7/IIS7.5 二级域名伪静态设置方法
			转载地址:http://www.admin5.com/article/20120107/402582.shtml 
- centos下配置java环境变量
			一. 需要配置的环境变量1. PATH环境变量.作用是指定命令搜索路径,在shell下面执行命令时,它会到PATH变量所指定的路径中查找看是否能找到相应的命令程序.我们需要把 jdk安装目录下的bin ... 
- 指定的参数已超出有效值的范围 参数名: utcDate   WebResource异常
			指定的参数已超出有效值的范围.参数名: utcDate 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息 ... 
- SQL语句中将Datetime类型转换为字符串类型
			0 Feb 22 2006 4:26PM CONVERT(CHAR(19), CURRENT_TIMESTAMP, 0) 1 02/22/06 CONVERT(CHAR(8), CURRENT_ ... 
