Visual Studio Code to create a C # project

Visual Studio Code is a cross-platform text editor, like any other text in a text editor, not only occupy the lower disk space, performance is relatively fast; in recent years due to the constant upgrades and many developers provide a large number of plug-ins, it has It has become a very powerful code editor. So when we created a number of small and medium sized projects or modify a file in the project, directly vscode it is very convenient.

Installation vscode

vscode Download https://code.visualstudio.com/

Installation and operation environment C # language, Visual Studio editor installed, then of course do not need to be installed

Download .NET Corehttps: //dotnet.microsoft.com/download

Then install the plug-in C # language in vscode,

Create a C # project

Open vscode, then add a workspace

after adding work space, a new terminal by vscode menu (shortcut Ctrl + Shift + `)

dotnet --help  //查看dotnet相关的帮助命令

Creating Solutions

PS D:\Projects\CSharp> dotnet new sln -o MyApp
已成功创建模板“Solution File”。

Create a class library project

Prime Minister into the project directory, then create a corresponding main program and library

PS D:\Projects\CSharp> cd .\MyApp\
PS D:\Projects\CSharp\MyApp> dotnet new classlib -o  MyApp.Model
已成功创建模板“Class library”。

正在处理创建后操作...
正在 MyApp.Model\MyApp.Model.csproj 上运行 "dotnet restore"...
  正在还原 D:\Projects\CSharp\MyApp\MyApp.Model\MyApp.Model.csproj 的包...
  正在生成 MSBuild 文件 D:\Projects\CSharp\MyApp\MyApp.Model\obj\MyApp.Model.csproj.nuget.g.props。
  正在生成 MSBuild 文件 D:\Projects\CSharp\MyApp\MyApp.Model\obj\MyApp.Model.csproj.nuget.g.targets。
  D:\Projects\CSharp\MyApp\MyApp.Model\MyApp.Model.csproj 的还原在 210.35 ms 内完成。

还原成功。

PS D:\Projects\CSharp\MyApp> dotnet new console -o  MyApp.HelloWorld
已成功创建模板“Console Application”。

正在处理创建后操作...
正在 MyApp.HelloWorld\MyApp.HelloWorld.csproj 上运行 "dotnet restore"...
  正在还原 D:\Projects\CSharp\MyApp\MyApp.HelloWorld\MyApp.HelloWorld.csproj 的包...
  正在生成 MSBuild 文件 D:\Projects\CSharp\MyApp\MyApp.HelloWorld\obj\MyApp.HelloWorld.csproj.nuget.g.props。
  正在生成 MSBuild 文件 D:\Projects\CSharp\MyApp\MyApp.HelloWorld\obj\MyApp.HelloWorld.csproj.nuget.g.targets。
  D:\Projects\CSharp\MyApp\MyApp.HelloWorld\MyApp.HelloWorld.csproj 的还原在 201.45 ms 内完成。

还原成功。

Add the library to your project

PS D:\Projects\CSharp\MyApp> dotnet sln add  .\MyApp.HelloWorld\MyApp.HelloWorld.csproj
已将项目“MyApp.HelloWorld\MyApp.HelloWorld.csproj”添加到解决方案中。
PS D:\Projects\CSharp\MyApp> dotnet sln add  .\MyApp.Model\MyApp.Model.csproj
已将项目“MyApp.Model\MyApp.Model.csproj”添加到解决方案中。

References between items in libraries

We first need to be added into the referenced assembly directory, and then execute the command reference

PS D:\Projects\CSharp\MyApp> cd .\MyApp.HelloWorld\
PS D:\Projects\CSharp\MyApp\MyApp.HelloWorld> dotnet add reference ../MyApp.Model/MyApp.Model.csproj
已将引用“..\MyApp.Model\MyApp.Model.csproj”添加到项目。

Compile and run the code

PS D:\Projects\CSharp\MyApp> dotnet build
PS D:\Projects\CSharp\MyApp> dotnet run --project MyApp.HelloWorld

Code debugging

vscode while supporting friendly interface code debugging, through F5 to start debugging

Guess you like

Origin www.cnblogs.com/zhuanghamiao/p/vscode-csharp.html