Skip to content

Commit 548b002

Browse files
authored
Support building assembly with Debug configuration (#2339)
1 parent e1f2361 commit 548b002

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

build.ps1

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
.PARAMETER Clean
3636
Cleans the build folder ./bin and rebuilds the assemblies.
3737
38+
.PARAMETER Configuration
39+
The configuration used to build the assemblies. Only used in combination with -Clean. Defaults to Release.
40+
3841
.PARAMETER LockedRestore
3942
Restore nuget packages using the nuget lock file. Useful only for CI.
4043
@@ -45,12 +48,17 @@
4548
$env:PESTER_BUILD_INLINE=1 environment variable is used to force inlining in files that don't provide
4649
the -Inline parameter. When this gets stuck, and you see your module inline even when it should not,
4750
use -Inline:$false to reset it to 0.
51+
52+
.PARAMETER Inline
53+
Builds the module as a single Pester.psm1-file, instead of dot-sourcing the files. This is the mode used in release build.
4854
#>
4955

5056
[CmdletBinding()]
5157
param (
5258
[switch] $Load,
5359
[switch] $Clean,
60+
[ValidateSet('Debug', 'Release')]
61+
[string] $Configuration = 'Release',
5462
[switch] $LockedRestore,
5563
[switch] $Inline,
5664
[switch] $Import
@@ -60,7 +68,7 @@ $ErrorActionPreference = 'Stop'
6068
Get-Module Pester | Remove-Module
6169

6270
if ($Clean -and $PSVersionTable.PSVersion -lt [version]'5.1') {
63-
throw "Clean build of Pester requires PowerShell 5.1 or greater. If you have already compiled the assemblies and only modified powershell-files, try calling ./build.ps1 without -Clean."
71+
throw 'Clean build of Pester requires PowerShell 5.1 or greater. If you have already compiled the assemblies and only modified powershell-files, try calling ./build.ps1 without -Clean.'
6472
}
6573

6674
if ($Clean -and (Test-Path "$PSScriptRoot/bin")) {
@@ -71,16 +79,16 @@ if ($Clean) {
7179
# Import-LocalizedData (and ModuleVersion-property) used as workaround due to unknown error on PS3 build with Test-ModuleManifest
7280
# and because Test-ModuleManifest needs the psd1 and psm1 to be complete, but we want to generate help for config from the type
7381
# so we need to build up here, and not after the module build, so xml based solution is better than one that validates the manifest
74-
$manifest = Import-LocalizedData -FileName "Pester.psd1" -BaseDirectory "$PSScriptRoot/src"
82+
$manifest = Import-LocalizedData -FileName 'Pester.psd1' -BaseDirectory "$PSScriptRoot/src"
7583
if (-not $LockedRestore) {
7684
dotnet restore "$PSScriptRoot/src/csharp/Pester.sln"
7785
}
78-
else {
86+
else {
7987
dotnet restore "$PSScriptRoot/src/csharp/Pester.sln" --locked-mode
8088
}
81-
dotnet build "$PSScriptRoot/src/csharp/Pester.sln" --no-restore --configuration Release -p:VersionPrefix="$($manifest.ModuleVersion)" -p:VersionSuffix="$($manifest.PrivateData.PSData.Prerelease)"
89+
dotnet build "$PSScriptRoot/src/csharp/Pester.sln" --no-restore --configuration $Configuration -p:VersionPrefix="$($manifest.ModuleVersion)" -p:VersionSuffix="$($manifest.PrivateData.PSData.Prerelease)"
8290
if (0 -ne $LASTEXITCODE) {
83-
throw "build failed!"
91+
throw 'build failed!'
8492
}
8593
}
8694

@@ -106,10 +114,10 @@ $content = @(
106114

107115
if ($Clean) {
108116
$content += @(
109-
, ("$PSScriptRoot/src/csharp/Pester/bin/Release/net452/Pester.dll", "$PSScriptRoot/bin/bin/net452/")
110-
, ("$PSScriptRoot/src/csharp/Pester/bin/Release/net452/Pester.pdb", "$PSScriptRoot/bin/bin/net452/")
111-
, ("$PSScriptRoot/src/csharp/Pester/bin/Release/netstandard2.0/Pester.dll", "$PSScriptRoot/bin/bin/netstandard2.0/")
112-
, ("$PSScriptRoot/src/csharp/Pester/bin/Release/netstandard2.0/Pester.pdb", "$PSScriptRoot/bin/bin/netstandard2.0/")
117+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net452/Pester.dll", "$PSScriptRoot/bin/bin/net452/")
118+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net452/Pester.pdb", "$PSScriptRoot/bin/bin/net452/")
119+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.dll", "$PSScriptRoot/bin/bin/netstandard2.0/")
120+
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.pdb", "$PSScriptRoot/bin/bin/netstandard2.0/")
113121
)
114122
}
115123

@@ -160,10 +168,10 @@ if ($Clean) {
160168
}
161169

162170
# generate help for config object and insert it
163-
$configuration = [PesterConfiguration]::Default
171+
$configObject = [PesterConfiguration]::Default
164172
$eol = [Environment]::NewLine
165-
$generatedConfig = foreach ($p in $configuration.PSObject.Properties.Name) {
166-
$section = $configuration.($p)
173+
$generatedConfig = foreach ($p in $configObject.PSObject.Properties.Name) {
174+
$section = $configObject.($p)
167175
"${p}:"
168176
foreach ($r in $section.PSObject.Properties.Name) {
169177
$option = $section.$r
@@ -174,9 +182,9 @@ if ($Clean) {
174182

175183
$p = "$PSScriptRoot/src/Pester.RSpec.ps1"
176184
# in older versions utf8 means with BOM
177-
$e = if ($PSVersionTable.PSVersion.Major -ge 7) { "utf8BOM" } else { "utf8" }
185+
$e = if ($PSVersionTable.PSVersion.Major -ge 7) { 'utf8BOM' } else { 'utf8' }
178186
$f = Get-Content $p -Encoding $e
179-
$sbf = [System.Text.StringBuilder]""
187+
$sbf = [System.Text.StringBuilder]''
180188
$generated = $false
181189
foreach ($l in $f) {
182190
if ($l -match '^(?<margin>\s*)Sections and options:\s*$') {
@@ -199,7 +207,7 @@ if ($Clean) {
199207
}
200208
}
201209
}
202-
elseif ($generated -and ($l -match "^\s*(.PARAMETER|.EXAMPLE).*")) {
210+
elseif ($generated -and ($l -match '^\s*(.PARAMETER|.EXAMPLE).*')) {
203211
$generated = $false
204212
}
205213

@@ -211,7 +219,7 @@ if ($Clean) {
211219
Set-Content -Encoding $e -Value $sbf.ToString().TrimEnd() -Path $p
212220

213221
# generate PesterConfiguration.Format.ps1xml to ensure list view for all sections
214-
$configSections = $configuration.GetType().Assembly.GetExportedTypes() | Where-Object { $_.BaseType -eq [Pester.ConfigurationSection] }
222+
$configSections = $configObject.GetType().Assembly.GetExportedTypes() | Where-Object { $_.BaseType -eq [Pester.ConfigurationSection] }
215223
# Get internal ctor as public ctor always returns instanceId = zero guid prior to PS v7.1.0
216224
$formatViewCtor = [System.Management.Automation.FormatViewDefinition].GetConstructors('Instance,NonPublic')
217225
# Generate listcontrol views for all configuration sections

0 commit comments

Comments
 (0)