Packaging on Mac OS X
Packaging is supported on Mac OSX systems. Packaged executables will contain the entire PowerShell and .NET runtime so destination systems will not need either of these installed.

Prerequisites

You will need to install the following in order to package on Mac OS X.
Once you have them installed, you can setup your script for packaging.

Configuration

You will need to create a Package.psd1 file in order to package. Here is an example configuration that will package the test.ps1 script and output it to the DownloadsYou need to ensure that you set the .NET framework version to netcoreapp31 and the platform to osx-x64.
1
@{
2
Root = '/Users/adamdriscoll/Downloads/test.ps1' # Root script to package. This is the main entry point for the package.
3
OutputPath = '/Users/adamdriscoll/Downloads/out' # The output directory for the packaging process.
4
Package = @{
5
Enabled = $true # Whether to package as an executable.
6
DotNetVersion = 'netcoreapp31'
7
PackageType = 'Console' # The type of executable to generate. Valid values are Service or Console.
8
PowerShellArguments = '' # Sets the arguments for the PowerShell process that is hosted within the executable. You can use arguments like -NoExit, -ExecutionPolicy and -NoProfile.
9
Platform = 'x64' # Sets the architecture of the executable. Can be either 'x86' or 'x64'
10
PowerShellVersion = '7.0.3' # You can specify Windows PowerShell or PowerShell 7 or later versions version (e.g. 7.0.0)
11
RuntimeIdentifier = 'osx-x64' # You can specify other runtimes like linux-x64 (See .NET Core runtime identifiers)
12
}
13
Bundle = @{
14
Enabled = $true # Whether to bundle multiple PS1s into a single PS1. Always enabled when Package is enabled.
15
Modules = $true # Whether to bundle modules into the package
16
}
17
}
Copied!
By default, some core modules are included. Additional modules will also be included when enabling the Modules bundle.

Running the Packager

You can run the packager by using the Merge-Script cmdlet of the PowerShell Pro Tools module. If you include the -Verbose flag, you will see output from the packaging process.
In this example, we have a script named test.ps1 with the following content.
1
"Hello. I'm running on $($PSVersionTable.OS)"
Copied!
You can install the PowerShell Pro Tools module and then run merge script against the package.psd1 file we created earlier.
1
Install-Module PowerShellProTools
2
Merge-Script -ConfigFile ./package.psd1 -Verbose
3
VERBOSE: Checking license
4
VERBOSE: OutputPath is /Users/adamdriscoll/Downloads/out
5
VERBOSE: Bundling /Users/adamdriscoll/Downloads/test.ps1
6
VERBOSE: Packaging /tmp/test.ps1
7
VERBOSE: Creating temp directory: /tmp/259a5b5f8e164250af2fb04c10e1b829
8
VERBOSE: Packaging modules...
9
VERBOSE: Checking dotnet version.
10
VERBOSE: Checking dotnet version.
11
VERBOSE: 5.0.102
12
13
VERBOSE: 5.0.102
14
15
VERBOSE: Creating package project.
16
VERBOSE: Using .NET Framework version: netcoreapp31
17
VERBOSE: Determining projects to restore...
18
Restored /tmp/259a5b5f8e164250af2fb04c10e1b829/test.csproj (in 1.22 sec).
19
20
VERBOSE: Determining projects to restore...
21
Restored /tmp/259a5b5f8e164250af2fb04c10e1b829/test.csproj (in 1.22 sec).
22
23
VERBOSE: Packaging /tmp/test.ps1 -> /Users/adamdriscoll/Downloads/out/test
24
VERBOSE: Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
25
Copyright (C) Microsoft Corporation. All rights reserved.
26
27
Determining projects to restore...
28
Restored /tmp/259a5b5f8e164250af2fb04c10e1b829/test.csproj (in 566 ms).
29
test -> /tmp/259a5b5f8e164250af2fb04c10e1b829/bin/Debug/netcoreapp3.1/osx-x64/test.dll
30
test -> /Users/adamdriscoll/Downloads/out
31
32
VERBOSE: Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
33
Copyright (C) Microsoft Corporation. All rights reserved.
34
35
Determining projects to restore...
36
Restored /tmp/259a5b5f8e164250af2fb04c10e1b829/test.csproj (in 566 ms).
37
test -> /tmp/259a5b5f8e164250af2fb04c10e1b829/bin/Debug/netcoreapp3.1/osx-x64/test.dll
38
test -> /Users/adamdriscoll/Downloads/out
Copied!
After the packaging process is done, you can run your executable.
Last modified 8mo ago