Compile a ScriptoForm
New-SADScriptoFormProject function, which is included in the SmartAceDesigns.ScriptoFormTemplates Powershell module, and customizing it per your design requirements. The executable is built with the Microsoft .NET framework using the latest Microsoft .NET SDK and can be targeted to one or more of the following supported frameworks:- .NET 4.8.x (Legacy)
- .NET 8.x (LTS-Legacy aka “Long Term Support (Legacy)”)
- .NET 9.x (STS aka “Standard Term Support”)
- .NET 10.x (LTS aka “Long Term Support”)
The client device used to run the compiled executable must have the matching .NET runtime installed in order to use it. You are responsible for ensuring your client devices have this installed based on the targeted framework(s) you compiling for:
- .NET Framework (Legacy) (Included with the default Windows OS installation)
- .NET Runtime (LTS-Legacy)
- .NET Runtime (STS)
- .NET Runtime (LTS)
Methods
Section titled “Methods”You have two options available to compile your ScriptoForm into an executable format: the dotnet CLI which is installed as part of the SDK or the Build-SADScriptoFormExecutable function which is included with the SmartAceDesigns.ScriptoFormTemplates PowerShell module and abstracts the use the dotnet CLI commands.
dotnet
Section titled “dotnet”- Open a PowerShell console and navigate to the “Build” subdirectory in your ScriptoForm Project directory.
- Run one or more of the following commands from within your “Build” subdirectory to target the specified .NET framework(s) you need:
The option compiles the ScriptoForm using the Microsoft .NET 4.8.x framework. The output executable is placed in the “\Release\Legacy” subdirectory in your project directory. The output directory can be changed by modifying the
-oargument.PowerShell dotnet publish -f net48 -v q -o "..\Release\Legacy"; dotnet clean -f net48 -v qThe option compiles the ScriptoForm using the Microsoft .NET 8.x framework. The output executable is placed in the “\Release\LTS-Legacy” subdirectory in your project directory. The output directory can be changed by modifying the
-oargument.PowerShell dotnet publish -f "net8.0-windows" -v q -o "..\Release\LTS-Legacy"; dotnet clean -f "net8.0-windows" -v qThe option compiles the ScriptoForm using the Microsoft .NET 9.x framework. The output executable is placed in the “\Release\STS” subdirectory in your project directory. The output directory can be changed by modifying the
-oargument.PowerShell dotnet publish -f "net9.0-windows" -v q -o "..\Release\STS"; dotnet clean -f "net9.0-windows" -v qThe option compiles the ScriptoForm using the Microsoft .NET 10.x framework. The output executable is placed in the “\Release\LTS” subdirectory in your project directory. The output directory can be changed by modifying the
-oargument.PowerShell dotnet publish -f "net10.0-windows" -v q -o "..\Release\LTS"; dotnet clean -f "net10.0-windows" -v q
Build-SADScriptoFormExecutable
Section titled “Build-SADScriptoFormExecutable”The SmartAceDesigns.ScriptoFormTemplates PowerShell module includes the Build-SADScriptoFormExecutable function to assist with compiling your ScriptoForm into an executable format. This is the recommended method to build your ScriptoForm executable.
- Open a PowerShell console and navigate to your ScriptoForm Project directory.
- Run one or more of the following commands from within the root of your ScriptoForm Project directory to target the specified .NET framework(s) you need:
The option compiles the ScriptoForm using the Microsoft .NET 4.8.x framework. The output executable is placed in the “\Release\Legacy” subdirectory in your project directory. The output directory can be changed by using the optional
-ReleaseFolderargument with the function call.PowerShell Build-SADScriptoFormExecutable -BuildTarget LegacyThe option compiles the ScriptoForm using the Microsoft .NET 8.x framework. The output executable is placed in the “\Release\LTS-Legacy” subdirectory in your project directory. The output directory can be changed by using the optional
-ReleaseFolderargument with the function call.PowerShell Build-SADScriptoFormExecutable -BuildTarget LTS-LegacyThe option compiles the ScriptoForm using the Microsoft .NET 9.x framework. The output executable is placed in the “\Release\STS” subdirectory in your project directory. The output directory can be changed by using the optional
-ReleaseFolderargument with the function call.PowerShell Build-SADScriptoFormExecutable -BuildTarget STSThe option compiles the ScriptoForm using the Microsoft .NET 10.x framework. The output executable is placed in the “\Release\LTS” subdirectory in your project directory. The output directory can be changed by using the optional
-ReleaseFolderargument with the function call.PowerShell Build-SADScriptoFormExecutable -BuildTarget LTSThe option compiles the ScriptoForm into an executable for all three supported Microsoft .NET frameworks. An output executable is placed in the “\Release\Legacy”, “\Release\LTS”, and “\Release\STS” subdirectories in your project directory.
PowerShell Build-SADScriptoFormExecutable -BuildTarget All
For more information on the Build-SADScriptoFormExecutable function and available parameters: Get-Help Build-SADScriptoFormExecutable -Full
Deep Dive
Section titled “Deep Dive”Build files
Section titled “Build files”New-SADScriptoFormProject function, the files needed to compile the executable are automatically included in project directory for you. This includes:DirectoryBuild
- Build.cs
- Build.csproj
New-SADScriptoFormProject function - no modification is needed.dotnet.exe CLI parses this file when building the executable to determine how to build it.Execution Process
Section titled “Execution Process”- The executable creates a temporary directory in the users “Temp” directory. By default, this is “C:\Users\username\AppData\Local\Temp” on the Windows computer. The name of the temporary directory created is a combination of the script name and a randomly generated GUID value (e.g. “Show-DemoForm-A92D3EAB-FB6C-4AE6-8580-77E4C24C24F8”). This allows mulitple instances of executable to be run at the same time, which each instance having its own unique extraction directory.
- The executable extracts the “Script.ps1” file, and any additional support files declared in the “Build.csproj” file, to the temporary directory.
- The executable launches that latest version of PowerShell detected on the system and not excluded with a command-line argument to the executable, based on a standard installation directory names, with “Script.ps1” as the “-File” argument.
- The user interacts with the ScriptoForm as designed.
- When the user closes the Form the PowerShell process exits.
- The executable deletes the temporary directory and all contents.
- The executable closes.
Command-line Arguments
Section titled “Command-line Arguments”The following optional command-line arguments can be used with the compiled executable to control how a ScriptoForm launches at runtime:
| Argument | Purpose | Notes |
|---|---|---|
| -exclude:all | Exclude PowerShell x.x.x versions | Do not use with other exclude arguments |
| -exclude:ps7 | Exclude PowerShell 7.x.x versions | Do not use with other exclude arguments |
| -debug | Show console window | Use individually or with an exclude argument |
Examples
Section titled “Examples”Display the PowerShell console, typically for debugging purposes, along with the ScriptoForm form:
Show-DemoForm.exe -debugForce the ScriptoForm to launch with Windows PowerShell 5.1:
Show-DemoForm.exe -exclude:allForce the ScriptoForm to launch with Windows PowerShell 5.1 and show the console window:
Show-DemoForm.exe -exclude:all -debugExclude PowerShell 7 but allow (future) newer versions such as PowerShell 8:
Show-DemoForm.exe -exclude:ps7