Skip to content

Commit

Permalink
Add app to print supported frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-litvinchik committed May 7, 2024
1 parent b5e03d8 commit 14c3801
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
deploy_key
common/
common/
bin/
obj/
14 changes: 14 additions & 0 deletions tools/PrintSupportedFrameworks/PrintSupportedFrameworks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NuGet.Protocol" Version="6.9.1" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions tools/PrintSupportedFrameworks/PrintSupportedFrameworks.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrintSupportedFrameworks", "PrintSupportedFrameworks.csproj", "{0A236E75-BDE9-4A8F-9A1A-C12531524B41}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0A236E75-BDE9-4A8F-9A1A-C12531524B41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A236E75-BDE9-4A8F-9A1A-C12531524B41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A236E75-BDE9-4A8F-9A1A-C12531524B41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A236E75-BDE9-4A8F-9A1A-C12531524B41}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DD42DDA9-CCB7-4CCF-80B5-207B1A7EDD58}
EndGlobalSection
EndGlobal
60 changes: 60 additions & 0 deletions tools/PrintSupportedFrameworks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Text;
using NuGet.Common;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;

//string packageName = "GroupDocs.Viewer";
string packageName = "GroupDocs.Viewer.CrossPlatform";

ILogger logger = NullLogger.Instance;
CancellationToken cancellationToken = CancellationToken.None;

SourceCacheContext cache = new SourceCacheContext();
SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();

IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
packageName,
includePrerelease: false,
includeUnlisted: false,
cache,
logger,
cancellationToken);

StringBuilder mdTable = new StringBuilder();
mdTable.AppendLine("| Package version | Target frameworks |");
mdTable.AppendLine("| --- | --- |");

foreach (IPackageSearchMetadata package in packages.OrderByDescending(p => p.Published))
{
//Console.WriteLine($"Version: {package.Identity.Version}");
//Console.WriteLine($"Description: {package.Published}");
//Console.WriteLine("Dependencies:");
//foreach (var dependencyGroup in package.DependencySets)
//{
// Console.WriteLine($" {dependencyGroup.TargetFramework.GetShortFolderName()}");
//}

var frameworks = package
.DependencySets
.Select(d => d.TargetFramework.GetShortFolderName())
.Select(d => d
.Replace("net20", ".NET Framework 2.0")
.Replace("net40", ".NET Framework 4.0")
.Replace("net462", ".NET Frameword 4.6.2")
.Replace("net6.0", ".NET 6.0")
.Replace("netstandard2.0", ".NET Standard 2.0")
.Replace("netstandard2.1", ".NET Standard 2.1")
);

string frameworksJoined = string.Join(", ", frameworks);
if (string.IsNullOrEmpty(frameworksJoined))
{
frameworksJoined = ".NET Framework 2.0";
}

string line = $"| [{package.Identity.Version}](https://www.nuget.org/packages/{packageName}/{package.Identity.Version}) | {frameworksJoined} |";
mdTable.AppendLine(line);
}

Console.WriteLine(mdTable.ToString());

0 comments on commit 14c3801

Please sign in to comment.