前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C# on Visual Studio Code

C# on Visual Studio Code

作者头像
绿巨人
发布2018-05-16 17:44:18
1.5K0
发布2018-05-16 17:44:18
举报
文章被收录于专栏:绿巨人专栏绿巨人专栏

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
代码语言:javascript
复制
{
    "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
代码语言:javascript
复制
{
    "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
代码语言:javascript
复制
{
    "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:
代码语言:javascript
复制
{
    "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
代码语言:javascript
复制
// Place your settings in this file to overwrite the default settings
{
    "files.autoSave": "afterDelay"
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-09-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • installation
  • Create a C# project
  • Build the project
  • Run the project
  • Useful User Settings
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档