• 使用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

  • 相关阅读:
    Hutool集合相关工具类CollUtil常用方法
    适合弱电行业用的项目管理系统,找企智汇项目管理系统!
    配置Java环境变量不生效的解决办法
    状态机引擎在vivo营销自动化中的深度实践 | 引擎篇02
    使用asp.net core web api创建web后台,并连接和使用Sql Server数据库
    前端面试手册
    JUC源码学习笔记3——AQS等待队列和CyclicBarrier,BlockingQueue
    【精通Java】集合类体系之List集合
    第2次实验:Ethernet
    黑群辉+腾讯云+frp内网穿透
  • 原文地址:https://blog.csdn.net/hefeng_aspnet/article/details/126603858