顯示具有 .Net Core 標籤的文章。 顯示所有文章
顯示具有 .Net Core 標籤的文章。 顯示所有文章

2025/02/26

打造自建 GitHub Actions 2.322 環境:在 Windows 11 設置 Self-Hosted Runner 並建置.Net Core專案

Windows 相較於 macOS 和 Linux 設置較為繁瑣
在 Windows 上設定 GitHub Actions Runner 需要額外的權限與步驟。請先 以管理員身份 開啟 PowerShell,然後執行以下指令:
下載並安裝 GitHub Actions Runner
# 回到 C:\
cd ..\..\

# 創建一個文件夾
mkdir actions-runner; cd actions-runner

# 下載最新的runner包
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.322.0/actions-runner-win-x64-2.322.0.zip -OutFile actions-runner-win-x64-2.322.0.zip

# 可選:驗證哈希值
if((Get-FileHash -Path actions-runner-win-x64-2.322.0.zip -Algorithm SHA256).Hash.ToUpper() -ne 'ace5de018c88492ca80a2323af53ff3f43d2c82741853efb302928f250516015'.ToUpper()){ throw 'Computed checksum did not match' }

# 解壓安裝程序
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/actions-runner-win-x64-2.322.0.zip", "$PWD")

# 配置 GitHub Actions runner
# 接著填入需要配置的設定即可
./config.cmd --url https://github.com/YourOrganization --token yourToken

MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.Sdk" because directory did not exist

因環境變數缺少MSBuildSDKsPath
MSBuildSDKsPath=C:\Program Files\dotnet\sdk\8.0.406\Sdks

參考資料:

2019/03/14

.Net Core Determine OS



using System;
using System.Runtime.InteropServices;

namespace ShowOSConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                Console.WriteLine(RuntimeInformation.OSDescription);
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                Console.WriteLine(RuntimeInformation.OSDescription);
            else
                Console.WriteLine(RuntimeInformation.OSDescription);

            Console.WriteLine("輸入任何鍵結束");
            Console.ReadKey();
        }
    }
}

Install .Net Core 2.2 on CentOS 7


# Import RPM Source
rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
# Update Pacakge
yum update -y
# Install .Net Core SDK
yum install -y dotnet-sdk-2.2

參考資料:
https://dotnet.microsoft.com/download/linux-package-manager/centos/sdk-current