Skip to content

Commit e87aa64

Browse files
authored
[Feat] Allow build version to be passed in to build.ps1 via command line (#2864)
1 parent 2a87dd0 commit e87aa64

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

build.ps1

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ Param(
2424
[string]$Target = "Default",
2525
[ValidateSet("Release", "Debug")]
2626
[string]$Configuration = "Release",
27+
[string]$ForceVersion = "0.0.0",
2728
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
28-
[string]$Verbosity = "Normal",
29+
[string]$Verbosity = "Normal",
2930
[switch]$WhatIf,
3031
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
3132
[string[]]$ScriptArgs
@@ -97,6 +98,7 @@ if (!(Test-Path $NugetPath)) {
9798
$Arguments = @{
9899
target=$Target;
99100
configuration=$Configuration;
101+
forceVersion=$ForceVersion;
100102
verbosity=$Verbosity;
101103
dryrun=$WhatIf;
102104
}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value };

build/Context.cs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Context : FrostingContext
99
{
1010
public string Target { get; set; }
1111
public new string Configuration { get; set; }
12+
public string ForceVersion { get; set; }
1213
public bool FormatCode { get; set; }
1314
public BuildVersion Version { get; set; }
1415

build/Lifetime.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public override void Setup(Context context, ISetupContext setupContext)
1212
{
1313
context.Target = context.Argument("target", "Default");
1414
context.Configuration = context.Argument("configuration", "Release");
15+
context.ForceVersion = context.Argument<string>("forceVersion", "0.0.0");
1516
context.FormatCode = context.Argument("formatCode", false);
1617

1718
context.Artifacts = "./packaging/";
@@ -46,7 +47,7 @@ public override void Setup(Context context, ISetupContext setupContext)
4647
ToolInstaller.DotNetToolInstall(context, "coverlet.console", "1.7.2", "coverlet");
4748

4849
// Calculate semantic version.
49-
context.Version = BuildVersion.Calculate(context);
50+
context.Version = context.ForceVersion != "0.0.0" ? new BuildVersion(context.ForceVersion, null, null) : BuildVersion.Calculate(context);
5051
context.Version.Prefix = context.Argument<string>("version", context.Version.Prefix);
5152
context.Version.Suffix = context.Argument<string>("suffix", context.Version.Suffix);
5253

0 commit comments

Comments
 (0)