Compare commits
1 Commits
3fb8e98eed
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c5a8b3b4c |
@@ -1,8 +1,8 @@
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[string]$SourceScript = (Join-Path $PSScriptRoot 'caffeine.ps1'),
|
[string]$SourceScript,
|
||||||
[string]$OutputDir = (Join-Path $PSScriptRoot 'dist'),
|
[string]$OutputDir,
|
||||||
[string]$BuildDir = (Join-Path $PSScriptRoot 'build'),
|
[string]$BuildDir,
|
||||||
[string]$ExeName = 'PortableCaffeine.exe',
|
[string]$ExeName = 'PortableCaffeine.exe',
|
||||||
[switch]$ConsoleTarget,
|
[switch]$ConsoleTarget,
|
||||||
[switch]$KeepExtractedSource
|
[switch]$KeepExtractedSource
|
||||||
@@ -11,6 +11,26 @@ param(
|
|||||||
Set-StrictMode -Version Latest
|
Set-StrictMode -Version Latest
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
# In Windows PowerShell 5.1, $PSScriptRoot may be empty during param default evaluation.
|
||||||
|
# Resolve script-relative defaults after the param block for compatibility.
|
||||||
|
$scriptRoot = if (-not [string]::IsNullOrWhiteSpace($PSScriptRoot)) {
|
||||||
|
$PSScriptRoot
|
||||||
|
} elseif ($MyInvocation.MyCommand.Path) {
|
||||||
|
Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
} else {
|
||||||
|
(Get-Location).Path
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrWhiteSpace($SourceScript)) {
|
||||||
|
$SourceScript = Join-Path $scriptRoot 'caffeine.ps1'
|
||||||
|
}
|
||||||
|
if ([string]::IsNullOrWhiteSpace($OutputDir)) {
|
||||||
|
$OutputDir = Join-Path $scriptRoot 'dist'
|
||||||
|
}
|
||||||
|
if ([string]::IsNullOrWhiteSpace($BuildDir)) {
|
||||||
|
$BuildDir = Join-Path $scriptRoot 'build'
|
||||||
|
}
|
||||||
|
|
||||||
function Get-CSharpFromCaffeineScript {
|
function Get-CSharpFromCaffeineScript {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[string]$ExePath = (Join-Path $PSScriptRoot 'dist\PortableCaffeine.exe'),
|
[string]$ExePath,
|
||||||
[string]$Subject = 'CN=Portable Caffeine Dev Code Signing',
|
[string]$Subject = 'CN=Portable Caffeine Dev Code Signing',
|
||||||
[string]$FriendlyName = 'Portable Caffeine Dev Code Signing (Self-Signed)',
|
[string]$FriendlyName = 'Portable Caffeine Dev Code Signing (Self-Signed)',
|
||||||
[ValidateSet('None', 'CurrentUser', 'LocalMachine')]
|
[ValidateSet('None', 'CurrentUser', 'LocalMachine')]
|
||||||
@@ -10,7 +10,7 @@ param(
|
|||||||
[int]$YearsValid = 5,
|
[int]$YearsValid = 5,
|
||||||
[switch]$ForceNewCertificate,
|
[switch]$ForceNewCertificate,
|
||||||
[string]$TimestampServer,
|
[string]$TimestampServer,
|
||||||
[string]$CerExportPath = (Join-Path $PSScriptRoot 'dist\PortableCaffeine-dev-signing.cer'),
|
[string]$CerExportPath,
|
||||||
[string]$PfxExportPath,
|
[string]$PfxExportPath,
|
||||||
[securestring]$PfxPassword
|
[securestring]$PfxPassword
|
||||||
)
|
)
|
||||||
@@ -18,6 +18,23 @@ param(
|
|||||||
Set-StrictMode -Version Latest
|
Set-StrictMode -Version Latest
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
# In Windows PowerShell 5.1, $PSScriptRoot may be empty during param default evaluation.
|
||||||
|
# Resolve script-relative defaults after the param block for compatibility.
|
||||||
|
$scriptRoot = if (-not [string]::IsNullOrWhiteSpace($PSScriptRoot)) {
|
||||||
|
$PSScriptRoot
|
||||||
|
} elseif ($MyInvocation.MyCommand.Path) {
|
||||||
|
Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
} else {
|
||||||
|
(Get-Location).Path
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrWhiteSpace($ExePath)) {
|
||||||
|
$ExePath = Join-Path $scriptRoot 'dist\PortableCaffeine.exe'
|
||||||
|
}
|
||||||
|
if ([string]::IsNullOrWhiteSpace($CerExportPath)) {
|
||||||
|
$CerExportPath = Join-Path $scriptRoot 'dist\PortableCaffeine-dev-signing.cer'
|
||||||
|
}
|
||||||
|
|
||||||
if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) {
|
if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) {
|
||||||
throw "This script is intended for Windows only."
|
throw "This script is intended for Windows only."
|
||||||
}
|
}
|
||||||
|
|||||||
5
tasks/lessons.md
Normal file
5
tasks/lessons.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Lessons
|
||||||
|
|
||||||
|
## 2026-02-24
|
||||||
|
|
||||||
|
- PowerShell 5.1 compatibility: do not use `$PSScriptRoot` (or other script-location variables) inside `param()` default expressions. Resolve script-relative defaults after the `param` block instead.
|
||||||
Reference in New Issue
Block a user