小白使用visual studio code——创建c#项目

1、打开vscode

小白使用visual studio code——创建c#项目_第1张图片

2、shift+ctrl+`

小白使用visual studio code——创建c#项目_第2张图片

3、创建名称为MyVscodeApp的解决方案:

[zeo@doris ~]$ pwd
/home/zeo
[zeo@doris ~]$ ls
Desktop  Documents  Downloads  Music  MyApp  Pictures  Public  Templates  Videos  VirtualBox VMs  vmware
[zeo@doris ~]$ dotnet new sln -o MyVscodeApp
The template "Solution File" was created successfully.
[zeo@doris ~]$ ls
Desktop    Downloads  MyApp        Pictures  Templates  VirtualBox VMs
Documents  Music      MyVscodeApp  Public    Videos     vmware

4、创建项目库,名称MyVscodeApp.Model


[zeo@doris ~]$ dotnet new classlib -o MyVscodeApp.Model
The template "Class library" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on MyVscodeApp.Model/MyVscodeApp.Model.csproj...
  Restore completed in 302.47 ms for /home/zeo/MyVscodeApp.Model/MyVscodeApp.Model.csproj.

Restore succeeded.

[zeo@doris ~]$ 

5、创建控制台项目,名称为MyVscodeApp.HelloWorld

[zeo@doris ~]$ dotnet new console -o MyVscodeApp.HelloWorld
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on MyVscodeApp.HelloWorld/MyVscodeApp.HelloWorld.csproj...
  Restore completed in 309.55 ms for /home/zeo/MyVscodeApp.HelloWorld/MyVscodeApp.HelloWorld.csproj.

Restore succeeded.

[zeo@doris ~]$ 

6、将刚才新建的两个项目添加到当前解决方案中

(1)先将它们移动到解决方案的目录下

[zeo@doris ~]$ ls
Desktop    Downloads  MyApp        MyVscodeApp.HelloWorld  Pictures  Templates  VirtualBox VMs
Documents  Music      MyVscodeApp  MyVscodeApp.Model       Public    Videos     vmware
[zeo@doris ~]$ ls MyVscodeApp
MyVscodeApp.sln
[zeo@doris ~]$ mv MyVscodeApp.HelloWorld MyVscodeApp
[zeo@doris ~]$ mv MyVscodeApp.Model MyVscodeApp
[zeo@doris ~]$ ls
Desktop  Documents  Downloads  Music  MyApp  MyVscodeApp  Pictures  Public  Templates  Videos  VirtualBox VMs  vmware
[zeo@doris ~]$ ls MyVscodeApp
MyVscodeApp.HelloWorld  MyVscodeApp.Model  MyVscodeApp.sln
[zeo@doris ~]$ 

(2)添加到解决方案中

[zeo@doris ~]$ ls MyVscodeApp
MyVscodeApp.HelloWorld  MyVscodeApp.Model  MyVscodeApp.sln
[zeo@doris ~]$ cd MyVscodeApp
[zeo@doris MyVscodeApp]$ ls
MyVscodeApp.HelloWorld  MyVscodeApp.Model  MyVscodeApp.sln
[zeo@doris MyVscodeApp]$ dotnet sln add ./MyVscodeApp.HelloWorld/MyVscodeApp.HelloWorld.csproj
Project `MyVscodeApp.HelloWorld/MyVscodeApp.HelloWorld.csproj` added to the solution.
[zeo@doris MyVscodeApp]$ dotnet sln add ./MyVscodeApp.Model/MyVscodeApp.Model.csproj
Project `MyVscodeApp.Model/MyVscodeApp.Model.csproj` added to the solution.
[zeo@doris MyVscodeApp]$ 

7、类库Model被控制台HelloWorld项目引用


[zeo@doris MyVscodeApp.HelloWorld]$ dotnet add reference  ../MyVscodeApp.Model/MyVscodeApp.Model.csproj
Reference `..\MyVscodeApp.Model\MyVscodeApp.Model.csproj` added to the project.
[zeo@doris MyVscodeApp.HelloWorld]$ 

8、编译


[zeo@doris MyVscodeApp.HelloWorld]$ dotnet build
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 316.75 ms for /home/zeo/MyVscodeApp/MyVscodeApp.HelloWorld/MyVscodeApp.HelloWorld.csproj.
  Restore completed in 316.74 ms for /home/zeo/MyVscodeApp/MyVscodeApp.Model/MyVscodeApp.Model.csproj.
  MyVscodeApp.Model -> /home/zeo/MyVscodeApp/MyVscodeApp.Model/bin/Debug/netstandard2.0/MyVscodeApp.Model.dll
  MyVscodeApp.HelloWorld -> /home/zeo/MyVscodeApp/MyVscodeApp.HelloWorld/bin/Debug/netcoreapp2.2/MyVscodeApp.HelloWorld.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.45
[zeo@doris MyVscodeApp.HelloWorld]$ 

9、运行

[zeo@doris MyVscodeApp]$ dotnet run --project MyVscodeApp.HelloWorld
Hello World!
[zeo@doris MyVscodeApp]$ 

10、 添加代码,进行测试

(1)在MyVscodeApp.Model中添加Student.cs

小白使用visual studio code——创建c#项目_第3张图片

(2)修改HelloWolrd项目中的Program.cs

小白使用visual studio code——创建c#项目_第4张图片

(3)编译、运行

[zeo@doris MyVscodeApp]$ dotnet build
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 75.42 ms for /home/zeo/MyVscodeApp/MyVscodeApp.Model/MyVscodeApp.Model.csproj.
  Restore completed in 75.42 ms for /home/zeo/MyVscodeApp/MyVscodeApp.HelloWorld/MyVscodeApp.HelloWorld.csproj.
  MyVscodeApp.Model -> /home/zeo/MyVscodeApp/MyVscodeApp.Model/bin/Debug/netstandard2.0/MyVscodeApp.Model.dll
  MyVscodeApp.HelloWorld -> /home/zeo/MyVscodeApp/MyVscodeApp.HelloWorld/bin/Debug/netcoreapp2.2/MyVscodeApp.HelloWorld.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.90
[zeo@doris MyVscodeApp]$ dotnet run --project MyVscodeApp.HelloWorld
I am tom, I am 15 years old. My student ID is 20200101.
[zeo@doris MyVscodeApp]$ 


参考:
Debug a .NET console application using Visual Studio Code - .NET | Microsoft Docs
Create a .NET class library using Visual Studio Code - .NET | Microsoft Docs
Test a .NET class library using Visual Studio Code - .NET | Microsoft Docs


遗留问题:

(1)安装的智能提示插件不起作用

(2)自定格式对齐快捷键不起作用

(3)新创建的cs文件开头没有自动添加“using system;”引用

(4)使用菜单快捷键编译运行

你可能感兴趣的:(vscode,c#,ide)