Skip to content

Commit

Permalink
feature: Update to handle net7/8 and platforms (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
glennawatson authored Oct 2, 2023
1 parent 075a7ae commit 7037125
Show file tree
Hide file tree
Showing 19 changed files with 1,121 additions and 1,195 deletions.
8 changes: 5 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
<IsTestProject>$(MSBuildProjectName.Contains('Tests'))</IsTestProject>
<DebugType>embedded</DebugType>
<Authors>Glenn Watson</Authors>
<Copyright>Copyright (c) 2021 ReactiveUI Association Inc</Copyright>
<Copyright>Copyright (c) 2021-$([System.DateTime]::Now.ToString(yyyy)) ReactiveUI Association Inc</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/reactivemarbles/NuGetHelpers</PackageProjectUrl>
<PackageDescription>Helpers for dealing with NuGet packages.</PackageDescription>
<PackageReadmeFile>README.md</PackageReadmeFile>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<Owners>glennawatson</Owners>
<PackageTags>system.reactive;propertychanged;inpc;reactive;functional</PackageTags>
<PackageReleaseNotes>https://github.com/reactivemarbles/NuGetHelpers/releases</PackageReleaseNotes>
Expand All @@ -36,16 +38,16 @@
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\LICENSE" Pack="true" PackagePath="LICENSE" />
<None Include="$(MSBuildThisFileDirectory)..\images\logo.png" Pack="true" PackagePath="\"/>
<None Include="$(MSBuildThisFileDirectory)..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.507" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.5.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
Expand Down
11 changes: 9 additions & 2 deletions src/ReactiveMarbles.NuGet.Helpers.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveMarbles.NuGet.Helpers", "ReactiveMarbles.NuGet.Helpers\ReactiveMarbles.NuGet.Helpers.csproj", "{A6ACA596-33A0-4B6C-AAEC-AE0599E0DBF7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A3413B04-DB68-4FA0-AB6E-6CF47398CFE9}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.build.targets = Directory.build.targets
stylecop.json = stylecop.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
197 changes: 98 additions & 99 deletions src/ReactiveMarbles.NuGet.Helpers/AssemblyHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2023 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

Expand All @@ -9,135 +9,134 @@
using System.Linq;
using System.Runtime.InteropServices;

namespace ReactiveMarbles.NuGet.Helpers
namespace ReactiveMarbles.NuGet.Helpers;

/// <summary>
/// Helps get details about assemblies.
/// </summary>
public static class AssemblyHelpers
{
private static readonly string[] AssemblyFileExtensions =
{
".winmd", ".dll", ".exe"
};

/// <summary>
/// Helps get details about assemblies.
/// Gets the assembly file extensions set.
/// </summary>
public static class AssemblyHelpers
public static ISet<string> AssemblyFileExtensionsSet { get; } = new HashSet<string>(AssemblyFileExtensions, StringComparer.InvariantCultureIgnoreCase);

/// <summary>
/// Finds the union metadata file.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="version">The version.</param>
/// <returns>The file if found.</returns>
public static string? FindUnionMetadataFile(string name, Version version)
{
private static readonly string[] AssemblyFileExtensions =
var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Windows Kits", "10", "UnionMetadata");

if (!Directory.Exists(basePath))
{
".winmd", ".dll", ".exe"
};

/// <summary>
/// Gets the assembly file extensions set.
/// </summary>
public static ISet<string> AssemblyFileExtensionsSet { get; } = new HashSet<string>(AssemblyFileExtensions, StringComparer.InvariantCultureIgnoreCase);

/// <summary>
/// Finds the union metadata file.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="version">The version.</param>
/// <returns>The file if found.</returns>
public static string? FindUnionMetadataFile(string name, Version version)
return null;
}

basePath = Path.Combine(basePath, FindClosestVersionDirectory(basePath, version));

if (!Directory.Exists(basePath))
{
var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Windows Kits", "10", "UnionMetadata");
return null;
}

if (!Directory.Exists(basePath))
{
return null;
}
var file = Path.Combine(basePath, name + ".winmd");

basePath = Path.Combine(basePath, FindClosestVersionDirectory(basePath, version));
return !File.Exists(file) ? null : file;
}

if (!Directory.Exists(basePath))
{
return null;
}
/// <summary>
/// Finds the windows metadata file.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="version">The version.</param>
/// <returns>The file if found.</returns>
public static string? FindWindowsMetadataFile(string name, Version? version)
{
// This is only supported on windows at the moment.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return null;
}

var file = Path.Combine(basePath, name + ".winmd");
var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Windows Kits", "10", "References");

return !File.Exists(file) ? null : file;
if (!Directory.Exists(basePath))
{
return FindWindowsMetadataInSystemDirectory(name);
}

/// <summary>
/// Finds the windows metadata file.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="version">The version.</param>
/// <returns>The file if found.</returns>
public static string? FindWindowsMetadataFile(string name, Version? version)
if (version is null)
{
// This is only supported on windows at the moment.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return null;
}
return null;
}

var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Windows Kits", "10", "References");
basePath = Path.Combine(basePath, FindClosestVersionDirectory(basePath, version));

if (!Directory.Exists(basePath))
{
return FindWindowsMetadataInSystemDirectory(name);
}
if (!Directory.Exists(basePath))
{
return FindWindowsMetadataInSystemDirectory(name);
}

if (version is null)
{
return null;
}
var file = Path.Combine(basePath, name + ".winmd");

basePath = Path.Combine(basePath, FindClosestVersionDirectory(basePath, version));
return !File.Exists(file) ? FindWindowsMetadataInSystemDirectory(name) : file;
}

if (!Directory.Exists(basePath))
private static string? FindWindowsMetadataInSystemDirectory(string name)
{
var file = Path.Combine(Environment.SystemDirectory, "WinMetadata", name + ".winmd");
return File.Exists(file) ? file : null;
}

private static string? FindClosestVersionDirectory(string basePath, Version version)
{
string? path = null;
foreach (var folder in new DirectoryInfo(basePath)
.EnumerateDirectories()
.Select(d => ConvertToVersion(d.Name))
.Where(v => v.Version != null)
.OrderByDescending(v => v.Version))
{
if (path == null || folder.Version >= version)
{
return FindWindowsMetadataInSystemDirectory(name);
path = folder.Name;
}

var file = Path.Combine(basePath, name + ".winmd");

return !File.Exists(file) ? FindWindowsMetadataInSystemDirectory(name) : file;
}

private static string? FindWindowsMetadataInSystemDirectory(string name)
{
var file = Path.Combine(Environment.SystemDirectory, "WinMetadata", name + ".winmd");
return File.Exists(file) ? file : null;
}
return path ?? version.ToString();
}

private static string? FindClosestVersionDirectory(string basePath, Version version)
[SuppressMessage("Design", "CA1031: Modify to catch a more specific exception type, or rethrow the exception.", Justification = "Deliberate usage.")]
private static (Version? Version, string? Name) ConvertToVersion(string name)
{
string RemoveTrailingVersionInfo()
{
string? path = null;
foreach (var folder in new DirectoryInfo(basePath)
.EnumerateDirectories()
.Select(d => ConvertToVersion(d.Name))
.Where(v => v.Version != null)
.OrderByDescending(v => v.Version))
var shortName = name;
var dashIndex = shortName.IndexOf('-');
if (dashIndex > 0)
{
if (path == null || folder.Version >= version)
{
path = folder.Name;
}
shortName = shortName.Remove(dashIndex);
}

return path ?? version.ToString();
return shortName;
}

[SuppressMessage("Design", "CA1031: Modify to catch a more specific exception type, or rethrow the exception.", Justification = "Deliberate usage.")]
private static (Version? Version, string? Name) ConvertToVersion(string name)
try
{
string RemoveTrailingVersionInfo()
{
var shortName = name;
var dashIndex = shortName.IndexOf('-');
if (dashIndex > 0)
{
shortName = shortName.Remove(dashIndex);
}

return shortName;
}

try
{
return (new Version(RemoveTrailingVersionInfo()), name);
}
catch (Exception)
{
return (null, null);
}
return (new Version(RemoveTrailingVersionInfo()), name);
}
catch (Exception)
{
return (null, null);
}
}
}
43 changes: 15 additions & 28 deletions src/ReactiveMarbles.NuGet.Helpers/ConsoleNuGetLoggerOutput.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
// Copyright (c) 2019-2023 ReactiveUI Association Incorporated. All rights reserved.
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;

namespace ReactiveMarbles.NuGet.Helpers
namespace ReactiveMarbles.NuGet.Helpers;

/// <summary>
/// Provides logging to the console.
/// </summary>
public class ConsoleNuGetLoggerOutput : INuGetLoggerOutput
{
/// <summary>
/// Provides logging to the console.
/// </summary>
public class ConsoleNuGetLoggerOutput : INuGetLoggerOutput
{
/// <inheritdoc/>
public void Debug(string data)
{
Console.WriteLine("[DEBUG]: " + data);
}
/// <inheritdoc/>
public void Debug(string data) => Console.WriteLine("[DEBUG]: " + data);

/// <inheritdoc/>
public void Error(string data)
{
Console.WriteLine("[ERROR]: " + data);
}
/// <inheritdoc/>
public void Error(string data) => Console.WriteLine("[ERROR]: " + data);

/// <inheritdoc/>
public void Info(string data)
{
Console.WriteLine("[INFO]: " + data);
}
/// <inheritdoc/>
public void Info(string data) => Console.WriteLine("[INFO]: " + data);

/// <inheritdoc/>
public void Warn(string data)
{
Console.WriteLine("[WARN]: " + data);
}
}
/// <inheritdoc/>
public void Warn(string data) => Console.WriteLine("[WARN]: " + data);
}
Loading

0 comments on commit 7037125

Please sign in to comment.