Skip to content
39 changes: 39 additions & 0 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,45 @@ assembly
}
}

# Save PSOptions to be restored by Restore-PSOptions
function Save-PSOptions {
param(
[ValidateScript({$parent = Split-Path $_;if($parent){Test-Path $parent}else{return $true}})]
[ValidateNotNullOrEmpty()]
[string]
$PSOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath 'psoptions.json'),

[ValidateNotNullOrEmpty()]
[object]
$Options = (Get-PSOptions -DefaultToNew)
)

$Options | ConvertTo-Json -Depth 3 | Out-File -Encoding utf8 -FilePath $PSOptionsPath
}

# Restore PSOptions
# Optionally remove the PSOptions file
function Restore-PSOptions {
param(
[ValidateScript({Test-Path $_})]
[string]
$PSOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath 'psoptions.json'),
[switch]
$Remove
)

$options = Get-Content -Path $PSOptionsPath | ConvertFrom-Json

if($Remove)
{
# Remove PSOptions.
# The file is only used to set the PSOptions.
Remove-Item -Path $psOptionsPath
}

Set-PSOptions -Options $options
}

$script:RESX_TEMPLATE = @'
<?xml version="1.0" encoding="utf-8"?>
<root>
Expand Down
8 changes: 3 additions & 5 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function Start-PSPackage {
# Zip symbols.zip to the root package
$zipSource = Join-Path $symbolsSource -ChildPath '*'
$zipPath = Join-Path -Path $Source -ChildPath 'symbols.zip'
$Script:Options | ConvertTo-Json -Depth 3 | Out-File -Encoding utf8 -FilePath (Join-Path -Path $source -ChildPath 'psoptions.json')
Save-PSOptions -PSOptionsPath (Join-Path -Path $source -ChildPath 'psoptions.json') -Options $Script:Options
Compress-Archive -Path $zipSource -DestinationPath $zipPath
}
finally
Expand Down Expand Up @@ -493,11 +493,9 @@ function Expand-PSSignedBuild
Restore-PSModuleToBuild -PublishPath $buildPath

$psOptionsPath = Join-Path $buildPath -ChildPath 'psoptions.json'
$options = Get-Content -Path $psOptionsPath | ConvertFrom-Json
Restore-PSOptions -PSOptionsPath $psOptionsPath -Remove

# Remove PSOptions.
# The file is only used to set the PSOptions.
Remove-Item -Path $psOptionsPath
$options = Get-PSOptions

$options.PSModuleRestore = $true

Expand Down
1 change: 1 addition & 0 deletions tools/releaseBuild/setReleaseTag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ param(
# VSTS passes it as 'refs/heads/release-v6.0.2'

$branchOnly = $Branch -replace '^refs/heads/';
$branchOnly = $branchOnly -replace '[_\-]'

if($ReleaseTag -eq 'fromBranch' -or !$ReleaseTag)
{
Expand Down