From e87aa64973860122e2c2ba6aa6634f8961c4cc99 Mon Sep 17 00:00:00 2001 From: Slyck Lizzie <19241000+SlyckLizzie@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:30:30 -0500 Subject: [PATCH] [Feat] Allow build version to be passed in to build.ps1 via command line (#2864) --- build.ps1 | 4 +++- build/Context.cs | 1 + build/Lifetime.cs | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/build.ps1 b/build.ps1 index e98303f2..2c490c62 100644 --- a/build.ps1 +++ b/build.ps1 @@ -24,8 +24,9 @@ Param( [string]$Target = "Default", [ValidateSet("Release", "Debug")] [string]$Configuration = "Release", + [string]$ForceVersion = "0.0.0", [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity = "Normal", + [string]$Verbosity = "Normal", [switch]$WhatIf, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$ScriptArgs @@ -97,6 +98,7 @@ if (!(Test-Path $NugetPath)) { $Arguments = @{ target=$Target; configuration=$Configuration; + forceVersion=$ForceVersion; verbosity=$Verbosity; dryrun=$WhatIf; }.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value }; diff --git a/build/Context.cs b/build/Context.cs index 6812eea0..ad1e6b5f 100644 --- a/build/Context.cs +++ b/build/Context.cs @@ -9,6 +9,7 @@ public class Context : FrostingContext { public string Target { get; set; } public new string Configuration { get; set; } + public string ForceVersion { get; set; } public bool FormatCode { get; set; } public BuildVersion Version { get; set; } diff --git a/build/Lifetime.cs b/build/Lifetime.cs index 21078a25..b46a3b43 100644 --- a/build/Lifetime.cs +++ b/build/Lifetime.cs @@ -12,6 +12,7 @@ public class Lifetime : FrostingLifetime { context.Target = context.Argument("target", "Default"); context.Configuration = context.Argument("configuration", "Release"); + context.ForceVersion = context.Argument("forceVersion", "0.0.0"); context.FormatCode = context.Argument("formatCode", false); context.Artifacts = "./packaging/"; @@ -46,7 +47,7 @@ public class Lifetime : FrostingLifetime ToolInstaller.DotNetToolInstall(context, "coverlet.console", "1.7.2", "coverlet"); // Calculate semantic version. - context.Version = BuildVersion.Calculate(context); + context.Version = context.ForceVersion != "0.0.0" ? new BuildVersion(context.ForceVersion, null, null) : BuildVersion.Calculate(context); context.Version.Prefix = context.Argument("version", context.Version.Prefix); context.Version.Suffix = context.Argument("suffix", context.Version.Suffix);