[comment]: # C# on Visual Studio Code

installation

.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
{
"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 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的更多相关文章

  1. Visual Studio Code 代理设置

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...

  2. 在Visual Studio Code中配置GO开发环境

    一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...

  3. Visual Studio Code——Angular2 Hello World 之 2.0

    最近看到一篇用Visual Studio Code开发Angular2的文章,也是一篇入门教程,地址为:使用Visual Studio Code開發Angular 2專案.这里按部就班的做了一遍,感觉 ...

  4. docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用

    .net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ...

  5. Visual Studio Code v0.9.1 发布

    微软的跨平台编辑器 Visual Studio Code v0.9.1 已经发布,官方博客上发布文章Visual Studio Code – October Update (0.9.1):http:/ ...

  6. 微软Visual Studio Code 0.8.0发布,新增多种主题

    月30日,Build 开发者大会上,正式宣布了 Visual Studio Code 项目;并将其定义为:一个运行于 Mac OS X.Windows和 Linux 之上的,针对于编写现代 Web 和 ...

  7. Visual Studio Code 配置指南

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器.在我看来它是「一款完美的编辑器」. 本文是有关 VS Code 的特性介绍与配置指 ...

  8. Visual Studio Code,完美的编辑器

    今日凌晨,微软的文本(代码)编辑器 Visual Studio Code(简称 VS Code),发布了首个正式版,距离首个 beta 版上线时间刚好一年. 在十多年的编程经历中,我使用过非常多的的代 ...

  9. 打造TypeScript的Visual Studio Code开发环境

    打造TypeScript的Visual Studio Code开发环境 本文转自:https://zhuanlan.zhihu.com/p/21611724 作者: 2gua TypeScript是由 ...

  10. Visual Studio Code 使用Git进行版本控制

    Visual Studio Code 使用Git进行版本控制 本来认为此类教程,肯定是满网飞了.今天首次使用VS Code的Git功能,翻遍了 所有中文教程,竟没有一个靠谱的.遂动笔写一篇. 请确保你 ...

随机推荐

  1. 利用nodejs+phantomjs+casperjs采集淘宝商品的价格

    因为一些业务需求需要采集淘宝店铺商品的销售价格,但是淘宝详情页面的价格显示是通过js动态调用显示的.所以就没法通过普通的获取页面html然后通过正则或者xpath的方式获取到想到的信息了. 所幸我们现 ...

  2. Copy15G的初始容量,注册就再送5G,邀请注册的人也送5G

    Copy15G的初始容量,注册就再送5G,邀请注册的人也送5G,可谓是史上最隆重最给力的容量赠送活动~~~https://copy.com?r=kFpfsZ

  3. hadoop 转

    detailed http://wenku.baidu.com/view/c2d1ebb4ba0d4a7302763a84.html http://hadoop.apache.org/docs/r1. ...

  4. 模拟登录神器之PHP基于cURL实现自动模拟登录类

    一.构思 从Firefox浏览器拷贝cURL命令(初始页.提交.提交后) 自动分析curl形成模拟登录代码 默认参数:ssl/302/gzip 二.实现 接口 (一)根据curl信息执行并解析结果 p ...

  5. 关于IT概念的一些思考

    同事提及“软件工程.软件生命周期.项目管理.CMMI.IPD.RUP.UML及UML建模.面向对象分析与设计.需求分析.系统分析与设计……等等,它们到底是什么?它们之间有什么关系?”   下面是个人见 ...

  6. Android showing LoadingView or EmptyView for Activity or Fragment

    这几天利用一些时间,整理了一下,写了一个简单的工具类,用来快速的显示LoadingView或者EmptyView,以前都是定义一个layout,根布局为FrameLayout,再在layout布局文件 ...

  7. C#简易播放器(基于开源VLC)

    可见光通信技术(Visible Light Communication,VLC)是指利用可见光波段的光作为信息载体,不使用光纤等有线信道的传输介质,而在空气中直接传输光信号的通信方式.LED可见光通信 ...

  8. 在android中如何通过点击edittext之外的部分使软键盘隐藏

    我们知道在android中点击edittext框就会自动弹出软键盘,那怎么通过点击edittext之外的部分使软键盘隐藏呢?(微信聊天时的输入框就是这个效果,这个给用户的体验还是很不错的) 首先我们要 ...

  9. VS2010打包,遇到的一些问题和解决办法

    我用的VS2010,教程很多,我就不一一介绍了,我把我自己遇到的一些问题向大家说一下: 1 可能我比较笨吧,没有理解网上很多教程的意思,直接把图片的后缀名改了,导致添加快捷方式图标的时候出现这种情况 ...

  10. bootstrap插件学习-bootstrap.carousel.js

    先看bootstrap.carousel.js的结构 var Carousel = function (element, options){} //构造器 Carousel.prototype = { ...