Skip to content

Support Files

Support files are additional external resources used by your ScriptoForm such as other PowerShell source files or data (JSON, CSV, TXT, etc.) files. For example you may have a PowerShell source file that contains a central list of PowerShell functions used by your ScriptoForm. A JSON file might be used to store a list of resources used to populate a ComboxBox or other list style control. Typically, these files are located in the root or sub-directory of your ScriptoForm project directory but can be located anywhere that is accessible by the user who runs the ScriptoForm.
These support files can be dot sourced or imported as normal by your ScriptoForm script. However, if you opt to compile your ScriptoForm into an executable with the intention of making it self-contained and not reliant on access to those original files, then these files should exist in your root project directory and additional steps must be taken to ensure that these files are included in the binary file along with the ScriptoForm script file.
When the support files are included in the compiled executable, a copy of them will be embedded into the executable as part of the compilation process and they will be extracted to the same temporary extraction directory as the ScriptForm when the executable is run. The ScriptoForm, when launched from the executable, can access those support files using the $PSScriptRoot variable which automatically points to that extraction directory:
PowerShell
$EnvironmentsFile = "$PSScriptRoot\environments.json"
The list of support files to be included in the executable are controlled by the Build.csproj file. As a ScriptoForm developer, you will update this file as needed depending on which support files should be included in your compiled executable.

The following provides an example of how to add the support file “Environments.txt” to the “Build.csproj” file.

  1. Open the “Build.csjproj” file with your code editor.

  2. Locate the <ItemGroup> node. By default it should look similar this this:

    \Build\Build.csproj
    <ItemGroup>
    <EmbeddedResource Include="..\Show-DemoForm.ps1">
    <LogicalName>Script.ps1</LogicalName>
    </EmbeddedResource>
    </ItemGroup>
  3. Add a new <EmbeddedResource> child node to the <ItemGroup> node, below the existing one, for each support file you needed to include:

    \Build\Build.csproj
    <ItemGroup>
    <EmbeddedResource Include="..\Show-DemoForm.ps1">
    <LogicalName>Script.ps1</LogicalName>
    </EmbeddedResource>
    <EmbeddedResource Include="..\Environments.txt">
    <LogicalName>Environments.txt</LogicalName>
    </EmbeddedResource>
    </ItemGroup>
    The Include= attribute value represents the location and file name of the support file relative to the “Build.csproj” file. Because “Build.csproj” is located in the “Build” sub-directory of your project, the ..\ indicates that the support file is currently located up one directory and in the root of the project directory:
    • DirectoryBuild
      • Build.cs
      • Build.csproj
    • .gitignore
    • Environments.txt
    • README.md
    • ScriptName.ps1

    The <LogicalName> child node text value represents the name to extract the file as when the executable is run.

  4. Save the changes to the “Build.csproj” file and compile your executable.