Code-server写个C#
安装.NET SDK
sudo apt update
sudo apt install wget
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt install dotnet-sdk-6.0
创建C#项目
在code-server
中创建一个新的 C#
控制台应用程序:
在 code-server
中打开终端 (Ctrl+Shift+t
或者 Terminal
> New Terminal
)。
使用 cd 命令切换到你希望存放项目的目录。
使用 dotnet new console
命令创建一个新的控制台
应用程序HelloWorld:
$ sudo dotnet new console -n HelloWorld
Welcome to .NET 6.0!
---------------------
SDK Version: 6.0.425
Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
The template "Console App" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on /home/coder/scripts/HelloWorld/HelloWorld.csproj...
Determining projects to restore...
Restored /home/coder/scripts/HelloWorld/HelloWorld.csproj (in 90 ms).
Restore succeeded.
编辑程序内容
然后进入HelloWorld路径
再在code-server中打开该文件夹,并编辑Program.cs文件,输入以下内容:
// See https://aka.ms/new-console-template for more information
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World! C# in code-server!");
}
}
}
文件权限
此时,可能遇到保存权限的问题。
sudo chown -R coder:coder /home/coder/scripts/
编译
~/scripts/HelloWorld$ dotnet build
MSBuild version 17.3.4+a400405ba for .NET
Determining projects to restore...
Restored /home/coder/scripts/HelloWorld/HelloWorld.csproj (in 119 ms).
HelloWorld -> /home/coder/scripts/HelloWorld/bin/Debug/net6.0/HelloWorld.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:03.23
运行
$ dotnet run
Hello, World! C# in code-server!
可以看到在terminal打印出HelloWorld。程序运行成功。