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
{
    "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"
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏大内老A

MS Enterprise Library 5.0发布!!

What is Enterprise Library Enterprise Library is a collection of reusable softwa...

18950
来自专栏黑白安全

windows命令执行漏洞不会玩? 看我!

经常有小伙伴碰到了命令执行漏洞不会玩,比如mssql注入点的命令执行,怎么来获取一个meterpreter?这个时候,就需要想办法来获取了,关于命令行来执行远程...

27340
来自专栏iOS技术

iOS RunLoop 深入探究

RunLoop是iOS或OSX开发中很重要的一个组件,它实现了很多底层的功能,本文主要分析RunLoop的概念、结构、运行原理,文中的结论主要是基于苹果官方文档...

40870
来自专栏张善友的专栏

IronPython整合Windows PowerShell

      Windows PowerShell 是微软为 Windows 环境所开发的 shell 及脚本语言技术,这项全新的技术提供了丰富的控制与自动化的系...

23970
来自专栏跟着阿笨一起玩NET

winform 关于Messagebox自动定时关闭

23010
来自专栏iOS技术杂谈

iOS多线程——RunLoop与GCD、AutoreleasePool你要知道的iOS多线程NSThread、GCD、NSOperation、RunLoop都在这里

你要知道的iOS多线程NSThread、GCD、NSOperation、RunLoop都在这里 转载请注明出处 https://cloud.tencent.co...

566110
来自专栏ASP.NETCore

.NET Core中ADO.NET SqlClient的使用与常见问题

  在很多要求性能的项目中,我们都要使用传统的ADO.NET的方式来完成我们日常的工作;目前有一些网友问有关于.NET Core操作SQL Server的问题在...

29410
来自专栏逍遥剑客的游戏开发

DirectX in C++/CLI

28550
来自专栏陈满iOS

iOS开发·RunLoop源码与用法完全解析(输入源,定时源,观察者,线程间通信,端口间通信,NSPort,NSMessagePort,NSMachPort,NSPortMessage)

OSX / iOS 系统中,提供了两个这样的对象:NSRunLoop 和 CFRunLoopRef。

39520
来自专栏张善友的专栏

Mono运行于IPhone之上

今晚看到Mono老大的blog上有一个Mono on the iPhone, 就是最近Sun公司还在为iPhone上运行Java 苹果没兴趣 Sun单干。 .N...

21460

扫码关注云+社区

领取腾讯云代金券