• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用VS Code 进行.NET 开发

武飞扬头像
csdn_aspnet
帮助1

今天我们就简单介绍如何使用vs code 进行.NET 开发,请自行安装 .NET6 等必要的编译环境。用vs code 进行.NET 开发,需要用到几个组件。

一、C#

学新通

二、Auto-Using for C#

学新通 

三、vscode-solution-explorer 

学新通

四、NuGet Package Manager GUI

学新通

五:C# Extensions

学新通 安装以上插件后,运行VS Code:

学新通

学新通 选择文件夹之后,即可打开现有项目了

学新通

VS Code 新建终端:

学新通

运行命令:dotnet --version,如下图:

学新通 生成项目:

学新通

 dotnet run --project xxxntry.csproj 

注意:运行上面命令,需在当前xxxntry.csproj所在目录执行,你可以使用cd 命令进入目录:cd xxxntry

生成成功

学新通

在浏览器输入此地址即可打开项目:

学新通

我这只是测试代码webapi,集成swagger,所以打开为swagger地址

同理,你可以使用dotnet build命令编译:

学新通

Ctrl C 停止运行

常用命令如下:

一.创建解决方案:

#创建解决方案 sln
dotnet new sln -n xxx

二.创建项目:

# 创建类库项目
dotnet new classlib -n xxx.Common

三.创建控制台应用程序

# 创建控制台应用程序
dotnet new console -n xxx.win

四.创建测试

# 创建xUnit单元测试项目
dotnet new xunit -n xxx.tests

五.添加引用和nuget引用

# 为 Tests 添加 Core 引用
dotnet add xxx.tests reference xxx.Common

# 为 项目添加 Nuget 引用
dotnet add xxx.Common package Hash --version 4.0.0

六.编译项目

#编译项目
dotnet build xxx.Common

七.单元测试

#执行单元测试,执行所有方法
dotnet test xxx.tests

#执行单元测试,指定的方法
dotnet test
xxx.tests --filter getUserName

八.运行项目

#运行
dotnet run --project xxx.win

九.发布项目

# 发布Release配置,包括 .net core 运行时,分别发布到 linux 和 windows
dotnet publish -c Release --self-contained -r linux-x64
dotnet publish -c Release --self-contained -r win-x64

# 发布Release配置,包括 .net core 运行时,指定目标框架 netcoreapp2.2
dotnet publish -c Release -f netcoreapp2.2 --self-contained -r linux-x64
dotnet publish -c Release -f netcoreapp2.2 --self-contained -r win-x64

dotnet run -c Release-f net6.0--runtimes net6.0  --self-contained -r win-x64 --未测试

# 发布Release配置,不包括 .net core 运行时
dotnet publish -c Release --self-contained false -r linux-x64
dotnet publish -c Release --self-contained false -r win-x64

# 发布Release配置,不包括 .net core 运行时,指定输出目录
dotnet publish -c Release --self-contained false -r linux-x64 -o C:\publish\linux-x64
dotnet publish -c Release --self-contained false -r win-x64 -o C:\publish\win-x64

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfjbibh
系列文章
更多 icon
同类精品
更多 icon
继续加载