[Feat] Allow build version to be passed in to build.ps1 via command line (#2864)

This commit is contained in:
Slyck Lizzie
2024-02-01 15:30:30 -05:00
committed by GitHub
parent 2a87dd0802
commit e87aa64973
3 changed files with 6 additions and 2 deletions

View File

@@ -24,8 +24,9 @@ Param(
[string]$Target = "Default", [string]$Target = "Default",
[ValidateSet("Release", "Debug")] [ValidateSet("Release", "Debug")]
[string]$Configuration = "Release", [string]$Configuration = "Release",
[string]$ForceVersion = "0.0.0",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Normal", [string]$Verbosity = "Normal",
[switch]$WhatIf, [switch]$WhatIf,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs [string[]]$ScriptArgs
@@ -97,6 +98,7 @@ if (!(Test-Path $NugetPath)) {
$Arguments = @{ $Arguments = @{
target=$Target; target=$Target;
configuration=$Configuration; configuration=$Configuration;
forceVersion=$ForceVersion;
verbosity=$Verbosity; verbosity=$Verbosity;
dryrun=$WhatIf; dryrun=$WhatIf;
}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value }; }.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value };

View File

@@ -9,6 +9,7 @@ public class Context : FrostingContext
{ {
public string Target { get; set; } public string Target { get; set; }
public new string Configuration { get; set; } public new string Configuration { get; set; }
public string ForceVersion { get; set; }
public bool FormatCode { get; set; } public bool FormatCode { get; set; }
public BuildVersion Version { get; set; } public BuildVersion Version { get; set; }

View File

@@ -12,6 +12,7 @@ public class Lifetime : FrostingLifetime<Context>
{ {
context.Target = context.Argument("target", "Default"); context.Target = context.Argument("target", "Default");
context.Configuration = context.Argument("configuration", "Release"); context.Configuration = context.Argument("configuration", "Release");
context.ForceVersion = context.Argument<string>("forceVersion", "0.0.0");
context.FormatCode = context.Argument("formatCode", false); context.FormatCode = context.Argument("formatCode", false);
context.Artifacts = "./packaging/"; context.Artifacts = "./packaging/";
@@ -46,7 +47,7 @@ public class Lifetime : FrostingLifetime<Context>
ToolInstaller.DotNetToolInstall(context, "coverlet.console", "1.7.2", "coverlet"); ToolInstaller.DotNetToolInstall(context, "coverlet.console", "1.7.2", "coverlet");
// Calculate semantic version. // 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<string>("version", context.Version.Prefix); context.Version.Prefix = context.Argument<string>("version", context.Version.Prefix);
context.Version.Suffix = context.Argument<string>("suffix", context.Version.Suffix); context.Version.Suffix = context.Argument<string>("suffix", context.Version.Suffix);