The process of developing my code tends to get more and more inconvenient due to how Startup.pps and Main function are handled.
The code of my app is launching differently depending on $Commandline having any value or not. The code inside the Startup.pps main function:
Code: Select all
if ($Commandline) {
if ((Show-Form1_psf) -eq 'OK') {
if ((Show-Form2_psf) -eq 'OK') { }
}
}
else {
if ((Show-Form2_psf) -eq 'OK') { }
}
Form1 and Form2 use the same functions taken from Global.ps1. I need to copy those functions from Global.ps1 into Startup.pps because otherwise, they aren't available. So every time when I modify the function inside Global.ps1 there is a chance that I forget to update it inside Startup.pps. It already causes some hard to discover bugs.
So I decided to create and use a workaround:
Startup.pss:
Code: Select all
#Define a Param block to use custom parameters in the project
#Param ($CustomParameter)
function Main {
Start-Main -Commandline $Commandline
}
Code: Select all
function Start-Main {
<#
.SYNOPSIS
The Start-Main function is called via Main function from Startup.pss.
.PARAMETER Commandline
$Commandline contains the complete argument string passed to the script packager executable.
.NOTES
Use this function to initialize your script and to call GUI forms.
.NOTES
To get the console output in the Packager (Forms Engine) use:
$ConsoleOutput (Type: System.Collections.ArrayList)
#>
param ([String]$Commandline)
<#
--------------------------------------------------------------------------
# TODO: Add initialization script here, load modules and check requirements
--------------------------------------------------------------------------
#>
if ((Show-AppUpdateReleaseAsset_psf) -eq 'OK') { }
#Set the exit code for the Packager
$script:ExitCode = 0
}
1. Does this workaround is valid? Does the scope of '$script:ExitCode' is correct after moving to Globals.ps1? I see no reason why it wouldn't work but If you see anything which requires correction then please advise.
2. Why the Startup.pps exist at all? Can't you just move 'Main' function into Global.ps1 and handle $Commandline there?