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

  • 相关阅读:
    【如何使用vscode用户代码】
    第三章 线性模型
    结构型设计模式- C++实现
    AC-PEG-NH2,Acrylate-PEG-Amine,丙烯酸酯PEG氨基含有PEG间隔基
    电脑软件:推荐八款图片处理工具,值得收藏
    如何保护IP在线隐私,提高网络安全?
    06-`Linux`的用户和用户组管理
    Linux常用命令
    查看docker容器中的ip
    uniapp——实现聊天室功能——技能提升
  • 原文地址:https://blog.csdn.net/hefeng_aspnet/article/details/126603858