小白使用visual studio code——之一创建c#项目
2021/10/25 12:39:54
本文主要是介绍小白使用visual studio code——之一创建c#项目,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、打开vscode
2、shift+ctrl+`
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
(2)修改HelloWolrd项目中的Program.cs
(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]$
遗留问题:
(1)安装的智能提示插件不起作用
(2)自定格式对齐快捷键不起作用
(3)新创建的cs文件开头没有自动添加“using system;”引用
(4)使用菜单快捷键编译运行
这篇关于小白使用visual studio code——之一创建c#项目的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#
- 2024-01-24Advanced .Net Debugging 1:你必须知道的调试工具