vak: (Default)
[personal profile] vak
Оказывается, с некоторых пор микрософтовскай язык C# и среда разработки .NET доступны на Ubuntu. Инструкция по установке здесь: https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu

Вот как выглядит установка на Ubuntu 20.10. Сначала добавляем Микрософт в список источников:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
sudo wget -q https://packages.microsoft.com/config/ubuntu/20.10/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
Теперь устанавливаем нужные пакеты:
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-5.0
Проверяем версию:
$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100
 Commit:    5044b93829

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.100/

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

.NET SDKs installed:
  5.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
Попробуем скомпилировать что-нибудь простое на языке C#. Создаём традиционный проект 'hello world'.
mkdir helloworld
cd helloworld
dotnet new console
dotnet build
Смотрим исходник:
$ cat Program.cs 
using System;

namespace helloworld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Запускаем:
$ dotnet run
Hello World!
Или так:
$ ./bin/Debug/net5.0/helloworld
Hello World!
Смотрим получившиеся бинарники:
$ size ./bin/Debug/net5.0/helloworld ./bin/Debug/net5.0/helloworld.dll
text data bss dec hex filename
129591 4785 144 134520 20d78 ./bin/Debug/net5.0/helloworld
3080 0 0 3080 c08 ./bin/Debug/net5.0/helloworld.dll
Не уверен, есть ли смысл в C# под Линуксом, но прикольно.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org