Linux下配置C#开发环境(dotnet core, vscode)

操作系统是CentOS 7.9

1,dotnet core 的安装在微软的网站的有比较详细的介绍。

参考:https://docs.microsoft.com/zh-cn/dotnet/core/install/linux
主要步骤为:

rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

安装dotnet core sdk 3.1(安装自己需要的版本)
使用yum源安装有点慢,海外网站通病

yum -y install dotnet-sdk-3.1

2,dotnet编译,安装好后输入dotnet -h能看到各种操作,比较常用的包括:

dotnet new 项目类型           # 创建的项目类型,如console
dotnet build                  # 编译
dotnet run                    # 运行

说明与示例:
使用普通用户而非root用户进行编程操作

# 创建目录
[netsky@localhost ~]$ mkdir Projects
[netsky@localhost ~]$ cd Projects/
[netsky@localhost Projects]$ mkdir Demo1
[netsky@localhost Projects]$ cd Demo1/
[netsky@localhost Demo1]$ pwd
/home/netsky/Projects/Demo1

# 创建console项目类型
[netsky@localhost Demo1]$ dotnet new console

# 当前目录生成相应的工程文件,默认生成Hello World.
[netsky@localhost Demo1]$ ll
total 8
-rw-rw-r--. 1 netsky netsky 178 May  1 23:47 Demo1.csproj
drwxrwxr-x. 2 netsky netsky 168 May  1 23:47 obj
-rw-rw-r--. 1 netsky netsky 187 May  1 23:47 Program.cs

# 编译
[netsky@localhost Demo1]$ dotnet build
Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  Demo1 -> /home/netsky/Projects/Demo1/bin/Debug/netcoreapp3.1/Demo1.dll

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

Time Elapsed 00:00:02.48

# 运行
[netsky@localhost Demo1]$ dotnet run
Hello World!
[netsky@localhost Demo1]$ 

3,如果使用可视化编译工具,可使用Visual Studio Code。

下址地址:https://code.visualstudio.com/#alt-downloads

标签: none

添加新评论