使用VS Code 进行.NET 开发

今天我们就简单介绍如何使用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

  • 9
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值