Open mthalman opened 2 years ago
I've prepared some changes for this work-item and shared in https://github.com/NikolaMilosavljevic/dotnet-docker/tree/powershell.templates
The changes were tested, but not sufficiently.
This work uses the second approach - to split Powershell commands into individual native commands, where possible. The only remaining Powershell command is for calculating the checksum.
This work would need to be modified and partly redone, due to changes I'm making for https://github.com/dotnet/dotnet-docker-internal/issues/5952
Our Dockerfiles are authored to execute multi-statement PowerShell scripts with statement semi-colon separators. This allows for multiple statements to be executed in a single command line. The issue with this is that it doesn't handle error conditions like we would want. If one of the statements is executing a native command, not a PowerShell cmdlet, and that command fails, execution of the PowerShell script will continue. This is in spite of the
$ErrorActionPreference
variable which only applies to cmdlets and functions. The exit code of the native command would not to be explicitly checked to handle things correctly. An example of a native command that gets called like this istar
which may end up failing.Note that PowerShell 7 has support for pipeline chain operators like
&&
and||
that do account for the exit code of native commands. However, we're often needing to execute PowerShell commands before PowerShell Core is even installed, so we are making use of the PowerShell 5 version installed in Windows Server Core.Options for solving this: