diff --git a/Build/Build.cs b/Build/Build.cs index 577bc41..45a473b 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -5,7 +5,7 @@ class Build : NukeBuild, IPublishPack, ICompileExample, ITest, IShowGitVersion, IPrePack { - bool IPack.UnlistNuget => true; + //bool IPack.UnlistNuget => true; bool ITest.TestBuildStopWhenFailed => false; public static int Main() => Execute(x => x.From().Build); } diff --git a/CHANGELOG.md b/CHANGELOG.md index 48dfcd8..aeb8501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.7.4] / 2023-02-08 +### Features +- Update `GetInformationalVersion` to find `nupkg` files. +### Added +- Add `NugetVersionInfo` to parse `nupkg` files by name. + ## [1.7.3] / 2023-12-18 ### Features - `IPack` with `UnlistNuget` to unlist nuget package. @@ -331,6 +337,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - First Release [vNext]: ../../compare/1.0.0...HEAD +[1.7.4]: ../../compare/1.7.3...1.7.4 [1.7.3]: ../../compare/1.7.2...1.7.3 [1.7.2]: ../../compare/1.7.1...1.7.2 [1.7.1]: ../../compare/1.7.0...1.7.1 diff --git a/ricaun.Nuke/Extensions/AssemblyExtension.cs b/ricaun.Nuke/Extensions/AssemblyExtension.cs index 7ec606a..67424ae 100644 --- a/ricaun.Nuke/Extensions/AssemblyExtension.cs +++ b/ricaun.Nuke/Extensions/AssemblyExtension.cs @@ -78,7 +78,19 @@ public static bool IsVersionPreRelease(this Project project) /// /// /// - public static string GetInformationalVersion(this Project project) => project.GetFileVersionInfo()?.ProductVersion.Split('+').First(); + /// Works with .dll and .nupkg + public static string GetInformationalVersion(this Project project) + { + if (project.GetFileVersionInfo() is FileVersionInfo fileVersionInfo) + { + return fileVersionInfo?.ProductVersion.Split('+').First(); + } + if (project.GetNugetVersionInfo() is NugetVersionInfo nugetVersionInfo) + { + return nugetVersionInfo?.ProductVersion.Split('+').First(); + } + return null; + } /// /// GetCompany => CompanyName @@ -131,6 +143,25 @@ public static FileVersionInfo GetFileVersionInfo(this Project project) return GetFileVersionInfoGreater(project.Directory, $"*{project.Name}*.dll"); } + /// + /// Get NugetVersionInfo of the first nupkg file found + /// + /// + /// + public static NugetVersionInfo GetNugetVersionInfo(this Project project) + { + var sourceDir = project.Directory; + var searchPattern = $"*{project.Name}*.nupkg"; + var nupkgFiles = Directory.GetFiles(sourceDir, searchPattern, SearchOption.AllDirectories); + foreach (var nupkgFile in nupkgFiles) + { + var nugetVersionInfo = NugetVersionInfo.Parse(nupkgFile); + if (nugetVersionInfo is NugetVersionInfo) return nugetVersionInfo; + } + + return null; + } + /// /// GetFileVersionInfoGreater /// @@ -169,8 +200,8 @@ public static void ShowInformation(this Project project) Serilog.Log.Information($"Name: {project.Name}"); Serilog.Log.Information($"GetAppId: {project.GetAppId()}"); - if (project.GetFileVersionInfo() == null) - Serilog.Log.Warning($"GetFileVersionInfo: {project.Name} not found!"); + if (project.GetInformationalVersion() == null) + Serilog.Log.Warning($"GetInformationalVersion: {project.Name} not found!"); Serilog.Log.Information($"GetInformationalVersion: {project.GetInformationalVersion()}"); Serilog.Log.Information($"GetAssemblyName: {project.GetAssemblyName()}"); diff --git a/ricaun.Nuke/Extensions/NuGetExtension.cs b/ricaun.Nuke/Extensions/NuGetExtension.cs index 0cab26d..dd3945e 100644 --- a/ricaun.Nuke/Extensions/NuGetExtension.cs +++ b/ricaun.Nuke/Extensions/NuGetExtension.cs @@ -2,9 +2,45 @@ using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.NuGet; using System; +using System.IO; namespace ricaun.Nuke.Extensions { + /// + /// NugetVersionInfo + /// + public class NugetVersionInfo + { + /// + /// ProductName + /// + public string ProductName { get; private set; } + /// + /// ProductVersion + /// + public string ProductVersion { get; private set; } + + /// + /// Parse and return a new instance of + /// + /// + /// + public static NugetVersionInfo Parse(string packageFileName) + { + string packageName; + string packageVersion; + if (NuGetExtension.TryGetPackageNameAndVersion(packageFileName, out packageName, out packageVersion)) + { + return new NugetVersionInfo + { + ProductName = packageName, + ProductVersion = packageVersion + }; + } + return null; + } + } + /// /// NuGetExtension /// @@ -31,6 +67,7 @@ public static bool TryGetPackageNameAndVersion(string packageFileName, out strin packageVersion = match.Groups[2].Value; return true; } + return false; } diff --git a/ricaun.Nuke/ricaun.Nuke.csproj b/ricaun.Nuke/ricaun.Nuke.csproj index 158bedb..268a310 100644 --- a/ricaun.Nuke/ricaun.Nuke.csproj +++ b/ricaun.Nuke/ricaun.Nuke.csproj @@ -7,7 +7,7 @@ ricaun.Nuke - 1.7.3 + 1.7.4