-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
722 lines (591 loc) · 26.7 KB
/
Copy pathbuild.ps1
File metadata and controls
722 lines (591 loc) · 26.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
<#
.SYNOPSIS
Build/pack orchestrator for the NameBuilder monorepo.
.DESCRIPTION
Builds the Dataverse plug-in (NameBuilder.dll) and/or the XrmToolBox configurator, and optionally:
- Packs the configurator into a NuGet package (including the plug-in payload under Assets).
- Deploys the configurator to a local XrmToolBox Plugins folder.
- Pushes the resulting .nupkg to NuGet.
Versioning rules (important for Dataverse / assembly binding behavior):
- Configurator package version is derived from the configurator AssemblyVersion.
- Plug-in AssemblyVersion is intentionally kept fixed.
- Plug-in AssemblyFileVersion may be bumped only when the plug-in changed in the last commit,
unless -SkipPluginFileVersionBump is supplied.
- When build-only mode is active (no packing), version metadata is not mutated.
.PARAMETER Configuration
Build configuration to use (Debug/Release).
.PARAMETER Pack
Enables packaging the configurator into a NuGet package. Without -Pack, the default behavior is build-only.
.PARAMETER PluginOnly
Build only the Dataverse plug-in.
.PARAMETER ConfiguratorOnly
Build only the configurator.
.PARAMETER Push
Push the generated NuGet package to the configured source. Only applies when packaging.
.PARAMETER SkipDeploy
Skips local deployment to the XrmToolBox Plugins folder.
.PARAMETER SkipVersionBump
Skips bumping the configurator AssemblyVersion (and therefore the NuGet package version).
.PARAMETER SkipPluginFileVersionBump
Skips bumping the plug-in AssemblyFileVersion.
.EXAMPLE
pwsh -File .\build.ps1 -Configuration Release
.EXAMPLE
pwsh -File .\build.ps1 -Configuration Release -Pack
.EXAMPLE
pwsh -File .\build.ps1 -Configuration Release -Pack -Push
#>
param(
[ValidateSet('Debug','Release')]
[string]$Configuration = "Release",
# Print what would happen and exit with no changes.
[switch]$DryRun,
# Build/pack toggles
[Alias('BuildOnly')]
[switch]$NoPack,
[Alias('PackOnly')]
[switch]$NoBuild,
# Component selection
[switch]$PluginOnly,
[switch]$ConfiguratorOnly,
# Convenience: build.ps1 defaults to build-only unless -Pack (or -NoBuild) is provided.
[switch]$Pack,
[string]$NugetSource = "https://api.nuget.org/v3/index.json",
[string]$NugetApiKey = $env:NUGET_API_KEY,
# Only push to NuGet when explicitly requested.
[switch]$Push,
[switch]$SkipPush,
[Alias('NoDeploy')]
[switch]$SkipDeploy,
# Skip bumping the configurator version (and therefore the NuGet package version).
# NOTE: plugin file-version bumping is controlled separately by -SkipPluginFileVersionBump
# and commit-based change detection.
[switch]$SkipVersionBump,
[switch]$SkipPluginRebuildIfUnchanged,
# Avoid modifying plugin version metadata.
[switch]$SkipPluginFileVersionBump,
[string]$XrmToolBoxPluginsPath = "$env:APPDATA\MscrmTools\XrmToolBox\Plugins"
)
# The plugin's AssemblyVersion is intentionally kept fixed to avoid binding issues.
# Only AssemblyFileVersion is allowed to increment.
$PluginFixedAssemblyVersion = "1.0.0.0"
$ErrorActionPreference = "Stop"
if ($PluginOnly -and $ConfiguratorOnly) {
throw 'Specify only one of -PluginOnly or -ConfiguratorOnly.'
}
if ($NoBuild -and $NoPack) {
Write-Warning 'Both -NoBuild and -NoPack were provided; nothing to do.'
return
}
# Preserve previous build.ps1 behavior:
# - Default is build-only (NoPack) unless -Pack is specified.
# - Pack-only (-NoBuild) implicitly enables packing.
$effectiveNoPack = [bool]($NoPack -or (-not $Pack -and -not $NoBuild))
# For build-only flows, avoid mutating version metadata.
$effectiveSkipVersionBump = [bool]($SkipVersionBump -or $effectiveNoPack)
$effectiveSkipPluginFileVersionBump = [bool]($SkipPluginFileVersionBump -or $effectiveNoPack)
if ($effectiveNoPack -and $Push) {
throw 'Cannot use -Push when build-only mode is active (no packaging). Add -Pack or remove -Push.'
}
$doBuild = -not $NoBuild
$doPack = -not $effectiveNoPack
$buildPlugin = -not $ConfiguratorOnly
$buildConfigurator = -not $PluginOnly
if ($doPack -and -not $buildConfigurator) {
throw 'Packing is only supported for the configurator package; remove -PluginOnly or add -ConfiguratorOnly.'
}
function Write-Info($message) {
Write-Host $message -ForegroundColor Cyan
}
function Get-AssemblyVersionFromAssemblyInfo {
param([string]$AssemblyInfoPath)
if (-not (Test-Path $AssemblyInfoPath)) {
throw "AssemblyInfo not found at $AssemblyInfoPath"
}
$content = Get-Content -Path $AssemblyInfoPath -Raw
$match = [regex]::Match($content, '(?m)^\s*\[assembly:\s*AssemblyVersion\("(?<ver>[^\"]+)"\)\]')
if (-not $match.Success) {
throw "AssemblyVersion attribute not found in $AssemblyInfoPath"
}
return $match.Groups['ver'].Value
}
function Get-AssemblyFileVersionFromAssemblyInfo {
param([string]$AssemblyInfoPath)
if (-not (Test-Path $AssemblyInfoPath)) {
throw "AssemblyInfo not found at $AssemblyInfoPath"
}
$content = Get-Content -Path $AssemblyInfoPath -Raw
$match = [regex]::Match($content, '(?m)^\s*\[assembly:\s*AssemblyFileVersion\("(?<ver>[^\"]+)"\)\]')
if (-not $match.Success) {
throw "AssemblyFileVersion attribute not found in $AssemblyInfoPath"
}
return $match.Groups['ver'].Value
}
function Increment-Revision {
param([string]$VersionString)
$parts = $VersionString.Split('.')
if ($parts.Count -lt 4) {
throw "Version must have 4 parts (Major.Minor.Build.Revision): $VersionString"
}
$major = [int]$parts[0]
$minor = [int]$parts[1]
$build = [int]$parts[2]
$revision = [int]$parts[3]
$revision++
return "$major.$minor.$build.$revision"
}
function Update-ConfiguratorVersion {
param([string]$AssemblyInfoPath)
if (-not (Test-Path $AssemblyInfoPath)) {
throw "AssemblyInfo not found at $AssemblyInfoPath"
}
$content = Get-Content -Path $AssemblyInfoPath -Raw
# Match only the actual assembly attribute line (avoid commented examples like 1.0.*)
$match = [regex]::Match($content, '(?m)^\s*\[assembly:\s*AssemblyVersion\("(?<ver>[^\"]+)"\)\]')
if (-not $match.Success) {
throw "AssemblyVersion attribute not found in $AssemblyInfoPath"
}
$current = $match.Groups['ver'].Value
$next = Increment-Revision -VersionString $current
# Keep AssemblyVersion and AssemblyFileVersion in sync for the configurator (attribute lines only)
$content = [regex]::Replace(
$content,
'(?m)^\s*\[assembly:\s*AssemblyVersion\("[^\"]*"\)\]',
('[assembly: AssemblyVersion("' + $next + '")]')
)
$content = [regex]::Replace(
$content,
'(?m)^\s*\[assembly:\s*AssemblyFileVersion\("[^\"]*"\)\]',
('[assembly: AssemblyFileVersion("' + $next + '")]')
)
Set-Content -Path $AssemblyInfoPath -Value $content -Encoding ascii
Write-Info "Incremented Configurator version: $current -> $next"
return $next
}
function Update-PluginFileVersion {
param([string]$AssemblyInfoPath)
if (-not (Test-Path $AssemblyInfoPath)) {
throw "AssemblyInfo not found at $AssemblyInfoPath"
}
$content = Get-Content -Path $AssemblyInfoPath -Raw
$asmVersionMatch = [regex]::Match($content, '(?m)^\s*\[assembly:\s*AssemblyVersion\("(?<ver>[^\"]+)"\)\]')
if (-not $asmVersionMatch.Success) {
throw "AssemblyVersion attribute not found in $AssemblyInfoPath"
}
$asmCurrent = $asmVersionMatch.Groups['ver'].Value
if ($asmCurrent -ne $PluginFixedAssemblyVersion) {
throw "Plugin AssemblyVersion must remain $PluginFixedAssemblyVersion (found $asmCurrent). Update the plugin file version only."
}
$fileVersionMatch = [regex]::Match($content, '(?m)^\s*\[assembly:\s*AssemblyFileVersion\("(?<ver>[^\"]+)"\)\]')
if (-not $fileVersionMatch.Success) {
throw "AssemblyFileVersion attribute not found in $AssemblyInfoPath"
}
$current = $fileVersionMatch.Groups['ver'].Value
$next = Increment-Revision -VersionString $current
# Preserve AssemblyVersion; only bump AssemblyFileVersion (attribute line only)
$content = [regex]::Replace(
$content,
'(?m)^\s*\[assembly:\s*AssemblyFileVersion\("[^\"]*"\)\]',
('[assembly: AssemblyFileVersion("' + $next + '")]')
)
# Safety: verify AssemblyVersion is still fixed after the edit
$asmAfterMatch = [regex]::Match($content, '(?m)^\s*\[assembly:\s*AssemblyVersion\("(?<ver>[^\"]+)"\)\]')
if (-not $asmAfterMatch.Success -or $asmAfterMatch.Groups['ver'].Value -ne $PluginFixedAssemblyVersion) {
$found = if ($asmAfterMatch.Success) { $asmAfterMatch.Groups['ver'].Value } else { "(missing)" }
throw "Plugin AssemblyVersion must remain $PluginFixedAssemblyVersion (found $found) after version update."
}
Set-Content -Path $AssemblyInfoPath -Value $content -Encoding ascii
Write-Info "Incremented Plugin file version: $current -> $next"
return $next
}
function Ensure-NugetExe {
$nugetDir = Join-Path $PSScriptRoot ".nuget"
$nugetExe = Join-Path $nugetDir "nuget.exe"
if (-not (Test-Path $nugetExe)) {
New-Item -ItemType Directory -Force -Path $nugetDir | Out-Null
$url = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
Write-Info "Downloading nuget.exe from $url"
Invoke-WebRequest -Uri $url -OutFile $nugetExe -UseBasicParsing | Out-Null
}
return $nugetExe
}
function Get-FileVersionInfoSafe {
param([string]$Path)
if (-not $Path -or -not (Test-Path $Path)) {
return $null
}
try {
return [System.Diagnostics.FileVersionInfo]::GetVersionInfo($Path)
} catch {
return $null
}
}
function Write-PluginVersionReport {
param(
[string]$PluginAssemblyInfo,
[string]$PluginBinDll,
[string]$PluginAssetsDll,
[string]$RebuildDecision
)
Write-Info "Plugin rebuild decision: $RebuildDecision"
try {
$asmVer = Get-AssemblyVersionFromAssemblyInfo -AssemblyInfoPath $PluginAssemblyInfo
$fileVer = Get-AssemblyFileVersionFromAssemblyInfo -AssemblyInfoPath $PluginAssemblyInfo
Write-Info "Plugin AssemblyInfo: AssemblyVersion=$asmVer AssemblyFileVersion=$fileVer"
} catch {
Write-Warning "Plugin AssemblyInfo: $($_.Exception.Message)"
}
$binInfo = Get-FileVersionInfoSafe -Path $PluginBinDll
if ($binInfo) {
Write-Info "Plugin binary (bin): $PluginBinDll"
Write-Info " FileVersion=$($binInfo.FileVersion) ProductVersion=$($binInfo.ProductVersion)"
}
if ($PluginAssetsDll -and (Test-Path $PluginAssetsDll)) {
$assetInfo = Get-FileVersionInfoSafe -Path $PluginAssetsDll
if ($assetInfo) {
Write-Info "Plugin binary (assets): $PluginAssetsDll"
Write-Info " FileVersion=$($assetInfo.FileVersion) ProductVersion=$($assetInfo.ProductVersion)"
}
}
}
function Test-IsInGitRepo {
try {
$null = & git rev-parse --show-toplevel 2>&1
return ($LASTEXITCODE -eq 0)
} catch {
return $false
}
}
function Test-PluginHasUncommittedChanges {
param([string]$PluginPath)
if (-not (Test-IsInGitRepo)) {
Write-Warning "Not in a git repository (or git not available); cannot check uncommitted changes"
return $false
}
$status = & git status --porcelain -- $PluginPath 2>&1
if ($status) {
Write-Info "Plugin has uncommitted changes"
return $true
}
return $false
}
function Test-PluginModifiedInLastCommit {
param([string]$PluginPath)
if (-not (Test-IsInGitRepo)) {
Write-Warning "Not in a git repository (or git not available); assuming plugin was modified in last commit"
return $true
}
try {
$lastCommitFiles = & git diff-tree --no-commit-id --name-only -r HEAD -- $PluginPath 2>&1
if ($LASTEXITCODE -eq 0 -and $lastCommitFiles) {
Write-Info "Plugin was modified in the last commit"
return $true
}
} catch {
Write-Warning "Could not check last commit; assuming plugin was modified"
return $true
}
Write-Info "Plugin was NOT modified in the last commit"
return $false
}
function Write-DryRunPlan {
param(
[string]$RepoRoot,
[string]$ConfigDir,
[string]$PluginDir,
[string]$ConfigAssemblyInfo,
[string]$PluginAssemblyInfo,
[bool]$DoBuild,
[bool]$DoPack,
[bool]$BuildPlugin,
[bool]$BuildConfigurator,
[bool]$SkipPluginBuild,
[bool]$PluginHasUncommittedChanges,
[bool]$PluginModifiedInLastCommit,
[string]$Configuration,
[bool]$SkipConfiguratorVersionBump,
[bool]$SkipPluginFileVersionBump,
[bool]$SkipDeploy,
[bool]$Push,
[bool]$SkipPush,
[string]$NugetSource,
[string]$NuspecPath,
[string]$NugetApiKey,
[bool]$NugetApiKeyWasExplicit
)
Write-Host ""
Write-Host "=== DRY RUN (no changes) ===" -ForegroundColor Yellow
Write-Info "RepoRoot: $RepoRoot"
Write-Info "Configuration: $Configuration"
Write-Info "Mode: DoBuild=$DoBuild DoPack=$DoPack"
Write-Info "Scope: BuildPlugin=$BuildPlugin BuildConfigurator=$BuildConfigurator"
$willPush = $Push -and (-not $SkipPush)
Write-Info "NuGet push: $willPush (Push=$Push SkipPush=$SkipPush)"
if ($willPush) { Write-Info "NuGet source: $NugetSource" }
$willDeploy = $BuildConfigurator -and $DoBuild -and (-not $SkipDeploy)
Write-Info "Deploy to XrmToolBox: $willDeploy (SkipDeploy=$SkipDeploy)"
# Versioning preview
try {
$cfgCurrent = Get-AssemblyVersionFromAssemblyInfo -AssemblyInfoPath $ConfigAssemblyInfo
$cfgNext = if ($DoBuild -and $BuildConfigurator -and (-not $SkipConfiguratorVersionBump)) { Increment-Revision -VersionString $cfgCurrent } else { $cfgCurrent }
Write-Info "Configurator version: $cfgCurrent -> $cfgNext"
if ($willPush) {
$pkgId = $null
if ($NuspecPath -and (Test-Path $NuspecPath)) {
try {
[xml]$x = Get-Content -Path $NuspecPath
$nsUri = $x.DocumentElement.NamespaceURI
$ns = New-Object System.Xml.XmlNamespaceManager($x.NameTable)
$ns.AddNamespace('n', $nsUri)
$idNode = $x.SelectSingleNode('//n:package/n:metadata/n:id', $ns)
if ($idNode -and -not [string]::IsNullOrWhiteSpace($idNode.InnerText)) {
$pkgId = $idNode.InnerText.Trim()
}
} catch { }
}
if ([string]::IsNullOrWhiteSpace($pkgId)) { $pkgId = 'NameBuilderConfigurator' }
$keyProvided = -not [string]::IsNullOrWhiteSpace($NugetApiKey)
$keyLen = if ($keyProvided) { $NugetApiKey.Length } else { 0 }
$keySource = if ($NugetApiKeyWasExplicit) { '-NugetApiKey parameter' } else { 'NUGET_API_KEY environment variable' }
$nupkg = Join-Path (Join-Path $RepoRoot 'artifacts\nuget') "$pkgId.$cfgNext.nupkg"
Write-Info "NuGet push details (dry-run):"
Write-Info " PackageId: $pkgId"
Write-Info " Version: $cfgNext"
Write-Info " Nupkg: $nupkg"
Write-Info " ApiKey: $keyProvided via $keySource (length=$keyLen)"
}
} catch {
Write-Warning "Configurator version: unable to read ($($_.Exception.Message))"
}
try {
$plugAsmCurrent = Get-AssemblyVersionFromAssemblyInfo -AssemblyInfoPath $PluginAssemblyInfo
$plugFileCurrent = Get-AssemblyFileVersionFromAssemblyInfo -AssemblyInfoPath $PluginAssemblyInfo
$plugFileNext = if ($DoBuild -and $BuildPlugin -and (-not $SkipPluginFileVersionBump) -and $PluginModifiedInLastCommit) { Increment-Revision -VersionString $plugFileCurrent } else { $plugFileCurrent }
Write-Info "Plugin AssemblyVersion: $plugAsmCurrent (unchanged)"
Write-Info "Plugin AssemblyFileVersion: $plugFileCurrent -> $plugFileNext"
Write-Info "Plugin change-detection: Uncommitted=$PluginHasUncommittedChanges ModifiedInLastCommit=$PluginModifiedInLastCommit SkipRebuildIfUnchanged=$SkipPluginBuild"
} catch {
Write-Warning "Plugin version: unable to read ($($_.Exception.Message))"
}
$assetsPluginDir = Join-Path $ConfigDir "Assets\DataversePlugin"
$pluginDll = Join-Path $PluginDir "bin\$Configuration\net462\NameBuilder.dll"
$configDll = Join-Path $ConfigDir "bin\$Configuration\NameBuilderConfigurator.dll"
$nuspecPath = Join-Path $ConfigDir "NameBuilderConfigurator.nuspec"
$outputDir = Join-Path $RepoRoot "artifacts\nuget"
Write-Info "Will ensure plugin payload under: $assetsPluginDir"
if ($DoBuild) {
if ($BuildPlugin -and (-not $SkipPluginBuild)) {
Write-Info "Would run: NameBuilderPlugin/build.ps1 (dotnet build)"
} elseif ($BuildPlugin) {
Write-Info "Would skip plugin build; would copy existing $pluginDll into assets if present"
}
if ($BuildConfigurator) {
Write-Info "Would run: NameBuilderConfigurator/build.ps1 (MSBuild)"
}
} else {
Write-Info "NoBuild: expects existing binaries"
Write-Info " Plugin DLL expected: $pluginDll (or already in assets)"
Write-Info " Configurator DLL expected: $configDll"
}
if ($DoPack) {
Write-Info "Would run: nuget.exe pack $nuspecPath -OutputDirectory $outputDir -BasePath $ConfigDir"
} else {
Write-Info "NoPack: would skip nuget pack"
}
Write-Info "Nuspec: $nuspecPath"
Write-Info "Output folder: $outputDir"
}
$repoRoot = (Resolve-Path -Path $PSScriptRoot).Path
$configDir = Join-Path $repoRoot "NameBuilderConfigurator"
$pluginDir = Join-Path $repoRoot "NameBuilderPlugin"
$configAssemblyInfo = Join-Path $configDir "Properties\AssemblyInfo.cs"
$pluginAssemblyInfo = Join-Path $pluginDir "Properties\AssemblyInfo.cs"
$pluginHasUncommitted = Test-PluginHasUncommittedChanges -PluginPath "NameBuilderPlugin"
$pluginModifiedInLastCommit = Test-PluginModifiedInLastCommit -PluginPath "NameBuilderPlugin"
$pluginHasAnyChangesForRebuild = ($pluginHasUncommitted -or $pluginModifiedInLastCommit)
$skipPluginBuild = $SkipPluginRebuildIfUnchanged -and (-not $pluginHasAnyChangesForRebuild)
if ($DryRun) {
$dryRunArgs = @{
RepoRoot = $repoRoot
ConfigDir = $configDir
PluginDir = $pluginDir
ConfigAssemblyInfo = $configAssemblyInfo
PluginAssemblyInfo = $pluginAssemblyInfo
DoBuild = $doBuild
DoPack = $doPack
BuildPlugin = $buildPlugin
BuildConfigurator = $buildConfigurator
SkipPluginBuild = $skipPluginBuild
PluginHasUncommittedChanges = $pluginHasUncommitted
PluginModifiedInLastCommit = $pluginModifiedInLastCommit
Configuration = $Configuration
SkipConfiguratorVersionBump = $effectiveSkipVersionBump
SkipPluginFileVersionBump = $effectiveSkipPluginFileVersionBump
SkipDeploy = [bool]$SkipDeploy
Push = [bool]$Push
SkipPush = [bool]$SkipPush
NugetSource = $NugetSource
NuspecPath = (Join-Path $configDir 'NameBuilderConfigurator.nuspec')
NugetApiKey = $NugetApiKey
NugetApiKeyWasExplicit = [bool]$PSBoundParameters.ContainsKey('NugetApiKey')
}
Write-DryRunPlan @dryRunArgs
return
}
if ($doBuild) {
if ($buildConfigurator) {
if ($effectiveSkipVersionBump) {
Write-Info "SkipVersionBump enabled (or build-only); leaving configurator version metadata unchanged."
} else {
Update-ConfiguratorVersion -AssemblyInfoPath $configAssemblyInfo | Out-Null
}
}
if ($buildPlugin) {
if ($effectiveSkipPluginFileVersionBump) {
Write-Info "SkipPluginFileVersionBump enabled (or build-only); leaving plugin version metadata unchanged."
} elseif ($pluginModifiedInLastCommit) {
Update-PluginFileVersion -AssemblyInfoPath $pluginAssemblyInfo | Out-Null
} else {
Write-Info "Plugin not modified in last commit; skipping plugin file version increment"
}
}
} else {
Write-Info "NoBuild enabled; skipping any version changes."
}
# Build Plugin (optional) and ensure plugin payload is present in configurator Assets
$pluginDll = Join-Path $pluginDir "bin\$Configuration\net462\NameBuilder.dll"
$pluginPdb = Join-Path $pluginDir "bin\$Configuration\net462\NameBuilder.pdb"
$assetsPluginDir = Join-Path $configDir "Assets\DataversePlugin"
New-Item -ItemType Directory -Force -Path $assetsPluginDir | Out-Null
$assetsPluginDll = Join-Path $assetsPluginDir "NameBuilder.dll"
$pluginDecision = $null
# If we were asked to skip the plugin rebuild but there are no binaries available yet,
# force a rebuild so packing/deploy doesn't fail on a clean workspace.
if ($skipPluginBuild -and $doBuild -and $buildPlugin) {
if (-not (Test-Path $pluginDll) -and -not (Test-Path $assetsPluginDll)) {
Write-Warning "Plugin binaries not found; forcing plugin rebuild despite -SkipPluginRebuildIfUnchanged."
$skipPluginBuild = $false
}
}
if (-not $doBuild) {
$pluginDecision = 'NoBuild (reuse existing binaries)'
} elseif ($buildPlugin -and (-not $skipPluginBuild)) {
$pluginDecision = 'Rebuild (plugin build will run)'
} elseif ($buildPlugin -and $skipPluginBuild) {
$pluginDecision = 'Skip rebuild (no plugin changes detected)'
} else {
$pluginDecision = 'Not requested (ConfiguratorOnly)'
}
if ($buildConfigurator -or $doPack) {
# The configurator package expects the plugin payload in Assets/DataversePlugin.
if ($buildPlugin -and $doBuild -and (-not $skipPluginBuild)) {
Write-Info "Building Plugin ($Configuration)..."
& pwsh -NoProfile -File (Join-Path $pluginDir "build.ps1") -Configuration $Configuration -Framework "net462" -Solution ".\NameBuilder.csproj" -TargetFolder $assetsPluginDir -RelativeFallback (Join-Path $configDir "Assets\DataversePlugin")
} else {
if ($skipPluginBuild) {
Write-Info "Plugin unchanged; skipping plugin build (using existing binaries)"
} elseif (-not $doBuild) {
Write-Info "NoBuild enabled; using existing plugin binaries"
}
if (Test-Path $pluginDll) {
Copy-Item -Path $pluginDll -Destination (Join-Path $assetsPluginDir "NameBuilder.dll") -Force
if (Test-Path $pluginPdb) {
Copy-Item -Path $pluginPdb -Destination (Join-Path $assetsPluginDir "NameBuilder.pdb") -Force
}
} elseif (-not (Test-Path (Join-Path $assetsPluginDir "NameBuilder.dll"))) {
throw "Plugin DLL not found at $pluginDll or $assetsPluginDir\NameBuilder.dll. Run a build at least once or remove -NoBuild."
}
}
} elseif ($buildPlugin -and $doBuild) {
# Plugin-only build.
Write-Info "Building Plugin ($Configuration)..."
& pwsh -NoProfile -File (Join-Path $pluginDir "build.ps1") -Configuration $Configuration -Framework "net462" -Solution ".\NameBuilder.csproj" -TargetFolder $assetsPluginDir -RelativeFallback (Join-Path $configDir "Assets\DataversePlugin")
}
# Report plugin version metadata and binary versions (whether rebuilt or reused)
Write-PluginVersionReport -PluginAssemblyInfo $pluginAssemblyInfo -PluginBinDll $pluginDll -PluginAssetsDll $assetsPluginDll -RebuildDecision $pluginDecision
# Build Configurator
if ($buildConfigurator -and $doBuild) {
Write-Info "Building Configurator ($Configuration)..."
$cfgBuildArgs = @(
'-NoProfile','-File', (Join-Path $configDir 'build.ps1'),
'-Configuration', $Configuration
)
# Root script owns version bumping; prevent double-bump.
$cfgBuildArgs += '-SkipVersionBump'
if ($SkipDeploy) { $cfgBuildArgs += '-SkipDeploy' }
Push-Location $configDir
try {
& pwsh @cfgBuildArgs
} finally {
Pop-Location
}
} elseif ($buildConfigurator -and $doPack) {
Write-Info "NoBuild enabled; expecting existing configurator build output for packing."
}
if (-not $buildConfigurator) {
return
}
# Determine version for NuGet package
$version = Get-AssemblyVersionFromAssemblyInfo -AssemblyInfoPath $configAssemblyInfo
$nugetExe = Ensure-NugetExe
$outputDir = Join-Path $repoRoot "artifacts\nuget"
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
$nuspecPath = Join-Path $configDir "NameBuilderConfigurator.nuspec"
if (-not (Test-Path $nuspecPath)) {
throw "Nuspec not found at $nuspecPath"
}
if ($doPack) {
Write-Info "Packing NameBuilderConfigurator v$version..."
& $nugetExe pack $nuspecPath -Version $version -OutputDirectory $outputDir -BasePath $configDir -NoPackageAnalysis
if ($LASTEXITCODE -ne 0) {
throw "nuget.exe pack failed with exit code $LASTEXITCODE"
}
} else {
Write-Info "NoPack enabled; skipping NuGet packaging."
return
}
$packagePath = Join-Path $outputDir "NameBuilderConfigurator.$version.nupkg"
if (-not (Test-Path $packagePath)) {
throw "NuGet package not created at $packagePath"
}
function Get-NuspecPackageId {
param([string]$NuspecPath)
try {
[xml]$x = Get-Content -Path $NuspecPath
$nsUri = $x.DocumentElement.NamespaceURI
$ns = New-Object System.Xml.XmlNamespaceManager($x.NameTable)
$ns.AddNamespace('n', $nsUri)
$id = $x.SelectSingleNode('//n:package/n:metadata/n:id', $ns)
if ($id -and -not [string]::IsNullOrWhiteSpace($id.InnerText)) {
return $id.InnerText.Trim()
}
} catch {
# fall through
}
return $null
}
if ($Push -and -not $SkipPush) {
if ([string]::IsNullOrWhiteSpace($NugetApiKey)) {
throw "NuGet API key not provided. Supply -NugetApiKey or set NUGET_API_KEY."
}
$pkgId = Get-NuspecPackageId -NuspecPath $nuspecPath
if ([string]::IsNullOrWhiteSpace($pkgId)) { $pkgId = 'NameBuilderConfigurator' }
$keyLen = $NugetApiKey.Length
$keySource = if ($PSBoundParameters.ContainsKey('NugetApiKey')) { '-NugetApiKey parameter' } else { 'NUGET_API_KEY environment variable' }
Write-Info "NuGet push details:"
Write-Info " PackageId: $pkgId"
Write-Info " Version: $version"
Write-Info " Nupkg: $packagePath"
Write-Info " Source: $NugetSource"
Write-Info " ApiKey: provided via $keySource (length=$keyLen)"
Write-Info "Pushing package to $NugetSource..."
& $nugetExe push $packagePath -ApiKey $NugetApiKey -Source $NugetSource
if ($LASTEXITCODE -ne 0) {
Write-Warning "nuget.exe push failed with exit code $LASTEXITCODE."
Write-Warning "If nuget.org returns 403, the API key is invalid/expired, or it is not permitted to push PackageId='$pkgId' (owner must have permission; scoped keys must include this ID)."
throw "nuget.exe push failed with exit code $LASTEXITCODE"
}
Write-Info "Package pushed successfully."
} else {
Write-Info "NuGet push skipped; package available at $packagePath"
}