visual studio code .net 开发

  Visual Studio确实是至关好用,各类简化操做什么的简直不要太舒服。但其容量太大,有时不是很方便,因此今天简单介绍一下另外一个工具--Visual Studio Code.linux

虽然相比于老大哥Visual Studio,VS Code有不少功能不完善,但它也更灵活轻便。而且VS Code还在不断的更新当中,目前的最新版本是18年11月更新的1.30版本,包含了 多行搜索改进 等内容。git

下面以.Net开发为例:github

不一样于Visual Studio,在VS Code上进行.Net开发你须要安装一些插件,点击左侧边栏箭头这个位置搜索web

 

安装插件 C# (C# for Visual Studio Code (powered by OmniSharp)) (必须)json

    Lightweight development tools for .NET Core.
    1. Great C# editing support, including Syntax Highlighting, IntelliSense, Go to Definition, Find
    All References, etc.
    Debugging support for .NET Core (CoreCLR). NOTE: Mono debugging is not supported. Desktop CLR debugging has limited support.
    Support for project.json and csproj projects on Windows, macOS and Linux.

安装插件 NuGet Package Manager (推荐,方便搜索,安装Nuget包) (推荐)windows

    Search the NuGet package repository for packages using either (partial or full) package name or another search term.
    Add PackageReference dependencies to your .NET Core 1.1+ .csproj or .fsproj files from Visual Studio Code's Command Palette.
    Remove installed packages from your project's .csproj or .fsproj files via Visual Studio Code's Command Palette.
    Handles workspaces with multiple .csproj or .fsproj files as well as workspaces with single .csproj/.fsproj files.
      1. For example:

 

    1. Ctrl + P Then Shift + > Choose "Nuget Package Manager: Add Package". Then Input the keyword about the Nuget Package. Finally, Choose the project you want to add the Nuget package.

VSCode 安装插件后通常须要从新激活以启用插件。因为VSCode自己不断更新,对于某些版本的VSCode可能须要重启应用,才能激活插件。
在VSCode中运行调试前,须要在.vscode路径下额外配置两个文件 launch.json tasks.json, 来告诉vscode如何启动项目。
Launch.json:app

{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
   "version": "0.2.0",
   "configurations": [
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceRoot}/MyABP.Web/bin/Debug/netcoreapp2.1/MyABP.Web.dll",
            "args": [],
            "cwd": "${workspaceRoot}/MyABP.Web",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "launchBrowser": {
                "enabled": true,
                "args": "${auto-detect-url}",
                "windows": {
                    "command": "cmd.exe",
                    "args": "/C start ${auto-detect-url}"
                },
                "osx": {
                    "command": "open"
                },
                "linux": {
                    "command": "xdg-open"
                }
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceRoot}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

若是你第一次运行某个项目,你须要确保全部引用的内容都存在,如上面的MyAbp.Web.dll文件.另外,这些配置不是固定不变的,你能够根据你的须要来进行不一样的配置。工具

如上面ui

"preLaunchTask": "build" 指定了你的项目在launch以前要先进行build操做。

又如
"env": {
                "ASPNETCORE_ENVIRONMENT": "Development" }
指定了你要在“哪一个环境”下启动你的项目。(实际上一个项目会有多种环境的配置,举个例子 appsetings.Development.json 和 appseting.QA.json用于区分不一样环境的配置,若是发如今QA环境出现了问题本地不能重现时,天然须要切换到目标环境来进行调试)


Tasks.json:url

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [
                "${workspaceRoot}/MyABP.Web/MyABP.Web.csproj"
            ],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        }
    ]
}

这里能够配置一下Task,如上面的

"preLaunchTask": "build" 具体的任务流程即在这里配置。

这里除去笔者使用的Web项目的配置外,固然还能够有多种其余项目应用的配置,如

 

 

这些配置完成以后,点击如图所示这个位置进入调试面板,而后点击上面的绿色三角就能够开始你的调试啦

 

/ **************************************************分割线*************************************************************/

vscode下经常使用DotNet命令
dotnet所使用的命令均可以使用 --help的方式来查看更详细的用法。
如dotnet --help
在项目开发过程当中,经常使用的命令有

dotnet new
用于新建内容,dotnet提供了许多模板,如Console Application, Class Library等等。
使用dotnet new时须要注意新建的项目是基于.Net Framework仍是基于.NetCore.
可使用 -f 来指定.

dotnet restore

主要是寻找当前目录下的项目文件(project.json),而后利用NuGet库还原整个项目的依赖库,而后遍历每一个目录,生成项目文件,继续还原该项目文件中的依赖项 --CSDN yangzhenping

如下命令不解释了,可使用 --help 查看具体用法

dotnet build dotnet run dotnet publish

相关文章
相关标签/搜索