dotnet Framework 수명 주기 도구
Source: Dev.to
소개
dotnet Global Tool을 만들어 .NET Core 프레임워크들의 릴리스 및 지원 종료(EOL) 정보를 나열하는 방법을 배웁니다.
💡 인수와 도움말을 지원하는 다양한 dotnet 도구 만들기에 관한 다른 글은
C# .NET Tools with System.CommandLine을 참고하세요.
이 도구는 매우 간단합니다. 대부분의 도구와 달리 필수 인수나 도움말이 없으며, 아래 URL에서 정보를 읽어와 화면에 표시합니다.
메인 코드
핵심 소스 코드 – CommonLibrary 프로젝트에 위치
using CommonLibrary.Models;
using System.Text.Json;
namespace CommonLibrary;
public static class DotNetReleaseService
{
private static readonly HttpClient _httpClient = new();
public static async Task> GetReleaseIndexAsync(
CancellationToken cancellationToken = default)
{
const string url = "https://dotnetcli.azureedge.net/dotnet/release-metadata/releases-index.json";
using HttpResponseMessage response = await _httpClient.GetAsync(url, cancellationToken);
response.EnsureSuccessStatusCode();
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken);
var root = await JsonSerializer.DeserializeAsync(
stream,
Options,
cancellationToken);
return root?.ReleasesIndex ?? [];
}
public static JsonSerializerOptions Options => new() { PropertyNameCaseInsensitive = true };
}
public sealed class ReleaseIndexItem
{
[JsonPropertyName("channel-version")]
public string? ChannelVersion { get; set; }
[JsonPropertyName("latest-release")]
public string? LatestRelease { get; set; }
[JsonPropertyName("latest-release-date")]
public DateTime? LatestReleaseDate { get; set; }
[JsonPropertyName("security")]
public bool Security { get; set; }
[JsonPropertyName("latest-runtime")]
public string? LatestRuntime { get; set; }
[JsonPropertyName("latest-sdk")]
public string? LatestSdk { get; set; }
[JsonPropertyName("product")]
public string? Product { get; set; }
/// <summary>
/// Gets or sets the support phase of the release.
/// </summary>
/// <remarks>
/// The support phase indicates the current lifecycle stage of the release,
/// such as "active", "preview", or "eol" (end of life).
/// </remarks>
[JsonPropertyName("support-phase")]
public string? SupportPhase { get; set; }
[JsonPropertyName("eol-date")]
public DateTime? EndOfLifeDate { get; set; }
[JsonPropertyName("release-type")]
public string? ReleaseType { get; set; }
[JsonPropertyName("releases.json")]
public string? ReleasesJsonUrl { get; set; }
}
public sealed class ReleasesIndexRoot
{
[JsonPropertyName("releases-index")]
public List? ReleasesIndex { get; set; }
}
엔트리 포인트 코드
소스 코드 – FrameworkLifeCycle 프로젝트에 위치
using CommonLibrary;
using Spectre.Console;
using SpectreConsoleLibrary.Core;
using System.CommandLine;
namespace FrameworkLifeCycle;
internal partial class Program
{
static async Task Main(string[] args)
{
RootCommand rootCommand = new("Get dotnet framework life cycles");
var releases = await DotNetReleaseService.GetReleaseIndexAsync();
SpectreConsoleHelpers.InfoPill(Justify.Left, $"Found {releases.Count} releases.");
Console.WriteLine();
var table = new Table().Title("[bold blue] .NET Release Information [/]");
table.AddColumn(new TableColumn("[bold yellow]Channel[/]"));
table.AddColumn(new TableColumn("[bold yellow]Latest[/]"));
table.AddColumn(new TableColumn("[bold yellow]ReleaseType[/]"));
table.AddColumn(new TableColumn("[bold yellow]End Of Life Date[/]"));
table.AddColumn(new TableColumn("[bold yellow]Support[/]"));
foreach (var item in releases)
{
var eolText = item.EndOfLifeDate.HasValue
? item.EndOfLifeDate.Value.ToString("MM/dd/yyyy")
: "Not set";
var releaseType = item.ReleaseType ?? "Unknown";
if (releaseType != "Unknown")
{
releaseType = releaseType.ToUpper();
}
table.AddRow(
FrameworkUtilities.IsProjectFramework(item.ChannelVersion ?? ""),
item.LatestRelease ?? "",
releaseType,
eolText,
Colorize(item.SupportPhase ?? "Unknown"));
}
AnsiConsole.Write(table);
Console.WriteLine();
}
private static string Colorize(string input) =>
input switch
{
{ } s when s.Contains("active", StringComparison.OrdinalIgnoreCase) => "[green]Active[/]",
{ } s when s.Contains("eol", StringComparison.OrdinalIgnoreCase) => "[red]eol[/]",
{ } s when s.Contains("preview", StringComparison.OrdinalIgnoreCase) => "[yellow]preview[/]",
_ => input,
};
}
프로젝트 파일
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<PackAsTool>true</PackAsTool>
<ToolCommandName>flc</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.0</Version>
</PropertyGroup>
<!-- Add any additional package references or settings as required for your project. -->
</Project>
요약
설치 후 flc 명령을 입력하면 모든 .NET Framework의 라이프 사이클을 나열합니다. 많은 개발자에게는 첫 번째 유용한 .NET 도구가 될 것입니다.
💡 인수와 도움말을 지원하는 .NET 도구 만들기에 대해 더 깊이 알고 싶다면, 제 다른 글을 참고하세요: C# .NET Tools with System.CommandLine.
