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。程序運行成功。

浙公網安備 33010602011771號