Visual Studio Code是一个支持跨平台的文本编辑器,同其他文本文本编辑器一样,不但占用磁盘空间小,性能也比较快;近几年由于不断的升级和许多开发者提供大量的插件,它已经成为了一个非常强大的代码编辑器。所以当我们创建一些中小型项目或者需要修改项目中的某个文件,直接使用vscode是非常方便的。

安装vscode

vscode下载地址https://code.visualstudio.com/

安装C#语言的运行环境,当然安装过Visual Studio编辑器的话是不需要再安装了

下载地址.NET Corehttps://dotnet.microsoft.com/download

然后在vscode中安装C#语言的插件

> [相关的文档:https://code.visualstudio.com/docs/languages/csharp](https://code.visualstudio.com/docs/languages/csharp)
> [视频介绍:https://channel9.msdn.com/Blogs/dotnet/Get-started-VSCode-Csharp-NET-Core-Windows](https://channel9.msdn.com/Blogs/dotnet/Get-started-VSCode-Csharp-NET-Core-Windows)

创建C#项目

打开vscode,然后添加一个工作空间

添加工作空间之后,通过vscode菜单新建一个终端(快捷键Ctrl+Shift+`)
```
dotnet --help //查看dotnet相关的帮助命令
```
####创建解决方案
```
PS D:\Projects\CSharp> dotnet new sln -o MyApp
已成功创建模板“Solution File”。
```
####创建项目类库
首相进入项目目录,然后再创建对应的主程序和类库
```
PS D:\Projects\CSharp> cd .\MyApp\
PS D:\Projects\CSharp\MyApp> dotnet new classlib -o MyApp.Model
已成功创建模板“Class library”。

正在处理创建后操作...

正在 MyApp.Model\MyApp.Model.csproj 上运行 "dotnet restore"...

正在还原 D:\Projects\CSharp\MyApp\MyApp.Model\MyApp.Model.csproj 的包...

正在生成 MSBuild 文件 D:\Projects\CSharp\MyApp\MyApp.Model\obj\MyApp.Model.csproj.nuget.g.props。

正在生成 MSBuild 文件 D:\Projects\CSharp\MyApp\MyApp.Model\obj\MyApp.Model.csproj.nuget.g.targets。

D:\Projects\CSharp\MyApp\MyApp.Model\MyApp.Model.csproj 的还原在 210.35 ms 内完成。

还原成功。

PS D:\Projects\CSharp\MyApp> dotnet new console -o MyApp.HelloWorld

已成功创建模板“Console Application”。

正在处理创建后操作...

正在 MyApp.HelloWorld\MyApp.HelloWorld.csproj 上运行 "dotnet restore"...

正在还原 D:\Projects\CSharp\MyApp\MyApp.HelloWorld\MyApp.HelloWorld.csproj 的包...

正在生成 MSBuild 文件 D:\Projects\CSharp\MyApp\MyApp.HelloWorld\obj\MyApp.HelloWorld.csproj.nuget.g.props。

正在生成 MSBuild 文件 D:\Projects\CSharp\MyApp\MyApp.HelloWorld\obj\MyApp.HelloWorld.csproj.nuget.g.targets。

D:\Projects\CSharp\MyApp\MyApp.HelloWorld\MyApp.HelloWorld.csproj 的还原在 201.45 ms 内完成。

还原成功。

####将类库添加到项目中

PS D:\Projects\CSharp\MyApp> dotnet sln add .\MyApp.HelloWorld\MyApp.HelloWorld.csproj

已将项目“MyApp.HelloWorld\MyApp.HelloWorld.csproj”添加到解决方案中。

PS D:\Projects\CSharp\MyApp> dotnet sln add .\MyApp.Model\MyApp.Model.csproj

已将项目“MyApp.Model\MyApp.Model.csproj”添加到解决方案中。

####项目中类库间的引用
首先需要进入到要添加引用的程序集目录中,然后执行引用命令

PS D:\Projects\CSharp\MyApp> cd .\MyApp.HelloWorld

PS D:\Projects\CSharp\MyApp\MyApp.HelloWorld> dotnet add reference ../MyApp.Model/MyApp.Model.csproj

已将引用“..\MyApp.Model\MyApp.Model.csproj”添加到项目。

####编译和运行代码

PS D:\Projects\CSharp\MyApp> dotnet build

PS D:\Projects\CSharp\MyApp> dotnet run --project MyApp.HelloWorld

###代码调试
vscode同时支持友好的界面代码调试,通过F5启动调试;启动调试时还需要我们添加调试的一些配置,可以通过vscode自动创建配置模板(launch.json和task.json),然后我们再对应进行修改

{

// Use IntelliSense to learn about possible attributes.

// Hover to view descriptions of existing attributes.

// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

"version": "0.2.0",

"configurations": [

{

"name": ".NET Core Launch (console)",

"type": "coreclr",

"request": "launch",

"preLaunchTask": "build",

"program": "${workspaceFolder}\MyApp\MyApp.HelloWorld\bin\Debug\netcoreapp2.2\MyApp.Apps.dll",

"args": [],

"cwd": "${workspaceFolder}",

"stopAtEntry": false,

"console": "internalConsole"

}

]

}

{

// See https://go.microsoft.com/fwlink/?LinkId=733558

// for the documentation about the tasks.json format

"version": "2.0.0",

"tasks": [

{

"label": "build",

"command": "dotnet",

"type": "shell",

"args": [

"build",

// Ask dotnet build to generate full paths for file names.

"${workspaceRoot}\MyApp",

"/property:GenerateFullPaths=true",

// Do not generate summary otherwise it leads to duplicate errors in Problems panel

"/consoleloggerparameters:NoSummary"

],

"group": "build",

"presentation": {

"reveal": "silent"

},

"problemMatcher": "$msCompile"

}

]

}

<div id="cnblogs_post_img"><img  src="https://img2018.cnblogs.com/blog/1735495/201908/1735495-20190831193750321-935813428.png"  alt=""  />
<img src="https://img2018.cnblogs.com/blog/1735495/201908/1735495-20190831201159417-1332105030.png" alt="" /></div>

Visual Studio Code创建C#项目的更多相关文章

  1. 如何使用Visual Studio Code开发Django项目

    如何获得 Visual Studio Code 访问 http://code.visualstudio.com 下载并安装. 前提条件 安装Python 2.7 及 Python 3.5,Window ...

  2. 使用Visual Studio Code创建第一个ASP.NET Core应用程序

    全文翻译自:Your First ASP.NET Core Application on a Mac Using Visual Studio Code 这篇文章将向你展示如何在Mac上写出你的第一个A ...

  3. Python_教程_使用Visual Studio Code开发Django项目

    如何获得 Visual Studio Code 访问 http://code.visualstudio.com 下载并安装. 前提条件 安装Python 2.7 及 Python 3.5,Window ...

  4. 根据官方文档使用Visual Studio Code创建代码组件的一些总结

    1.安装组件Visual Studio Code Download Visual Studio Code - Mac, Linux, Windows 2.安装Node.js Download | No ...

  5. 总结在Visual Studio Code创建Node.js+Express+handlebars项目

    一.安装node.js环境. Node.js安装包及源码下载地址为:https://nodejs.org/en/download/ 32 位安装包下载地址 : https://nodejs.org/d ...

  6. Visual Studio Code create the aps.net core project(Visual Studio Code 创建asp.net core项目)

    Install the C# plug-in as shown below: Perfom the dotnet new --help command as shown below: Enter a ...

  7. 开发者说 | 使用Visual Studio Code编译、调试Apollo项目

    转载地址:https://mp.weixin.qq.com/s?__biz=MzI1NjkxOTMyNQ==&mid=2247484266&idx=1&sn=d6bcd4842 ...

  8. 在Visual Studio Code中开发Office Add-in

    作者:陈希章 发表于 2017年7月13日 上一篇 我介绍了如何在Visual Studio中开发Office Add-in,因为有标准的项目模板,一系列配套的工具,尤其是自带的一键调试功能,可以让开 ...

  9. 1 分钟上手,在容器中运行 Visual Studio Code

    https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers 这个插件允许我们在容器中运 ...

随机推荐

  1. Linux-CentOS-Nginx安装

    原文转自 jerryhe326:https://www.cnblogs.com/jerrypro/p/7062101.html 一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装n ...

  2. ios webview

    //#pragma mark - UIWebView Delegate Methods -(void)webViewDidFinishLoad:(UIWebView *)webView{ //获取到w ...

  3. 通过Request对象获取请求的IP地址

    /** * 标识要从哪些消息头中获取IP地址 */ private static final String[] getIpArray = {"HTTP_X_FORWARDED_FOR&quo ...

  4. 10-numpy笔记-np.random.randint

    b_idx = np.random.randint(0, 9, 90) >>> b_idx array([0, 1, 5, 4, 7, 2, 7, 0, 0, 4, 2, 2, 3, ...

  5. Mysql数据库基础命令

    删除一个表: drop table if exists 表名; 在表中插入行: Insert into 表名 values(, , ,) 创建表: Create table 表名( Id int(10 ...

  6. 数据结构——链队列(linked queue)

    /* linkedQueue.c */ /* 链队列 */ #include <stdio.h> #include <stdlib.h> #include <stdboo ...

  7. 关于几类STL容器swap的复杂度问题

    \(swap\)的方式有 \(S1.swap(S2)\) 或 \(swap(S1,S2)\) \(vector,map,set,deque \ \ \ \ swap\)复杂度:\(O(1)\) \(p ...

  8. [ZJOI2019]线段树(线段树,DP)

    又是神仙题. 要写博客太长了,先咕着.放个代码先. 为什么 fmul 在 linux 底下还被定义过了--能想象到我一发 CE 的绝望吗 qaq #include<bits/stdc++.h&g ...

  9. Linux性能优化实战学习笔记:第四十讲

    一.上节回顾 上一节,我们学习了碰到分布式拒绝服务(DDoS)的缓解方法.简单回顾一下,DDoS利用大量的伪造请求,导致目标服务要耗费大量资源,来处理这些无效请求,进而无法正常响应正常用户的请求. 由 ...

  10. AtCoder Grand Contest 037 简要题解

    从这里开始 题目目录 Problem A Dividing a String 猜想每段长度不超过2.然后dp即可. 考虑最后一个长度大于等于3的一段,如果划成$1 + 2$会和后面相同,那么划成$2 ...