build
napt.build
PSADT package building for NAPT.
Builds PSAppDeployToolkit packages from recipes and downloaded installers: PSADT release management, script generation, file copying, and branding application.
Modules:
| Name | Description |
|---|---|
manager |
Package building orchestration (build_package). |
installer |
Finding the installer to build and reading it once. |
layout |
The versioned build folder, PSADT copy, installer copy, branding. |
commands |
Install/uninstall commands for MSI and MSIX installers. |
template |
Invoke-AppDeployToolkit.ps1 generation. |
scripts |
Detection and requirements scripts written beside a build. |
manifest |
The build manifest written by build and read by package and upload. |
packager |
.intunewin package creation (create_intunewin). |
icons |
Icon extraction from installers. |
registry_scripts |
Detection/requirements script generation (registry). |
msix_scripts |
Detection/requirements script generation (MSIX). |
napt.build.manager
Build manager for PSADT package creation.
Sequences a build from a recipe and a downloaded installer. The steps live in the modules they belong to:
- installer: the release to build, the installer file whose hash matches it, and what that file says about itself.
- layout: the versioned build folder, the PSADT template and installer copied into it, and the brand pack.
- commands: the install and uninstall commands for MSI and MSIX installers.
- template: the generated Invoke-AppDeployToolkit.ps1.
- scripts: the detection and requirements scripts.
- manifest: the record left beside the build.
Design Principles
- The release to build comes from deployment state; the installer is the file in that version's download folder whose SHA-256 matches
- The installer is read once; every later step uses what was read
- Entire PSADT Template_v4 structure copied unmodified
- Invoke-AppDeployToolkit.ps1 is generated from template (not copied)
- Build directories are versioned: {app_id}/{version}/
- Branding applied by replacing files in root Assets/ directory (v4 structure)
BuildResult
dataclass
Result from building a PSADT package.
Attributes:
| Name | Type | Description |
|---|---|---|
app_id |
str
|
Unique application identifier. |
app_name |
str
|
Application display name. |
version |
str
|
Application version. |
build_dir |
Path
|
Path to the build directory (packagefiles subdirectory). |
psadt_version |
str
|
PSADT version used for the build. |
Source code in napt/build/manager.py
build_package
build_package(
recipe_path: Path,
downloads_dir: Path | None = None,
output_dir: Path | None = None,
state_dir: Path | None = None,
) -> BuildResult
Builds a PSADT package from a recipe and downloaded installer.
This is the main entry point for the build process. It:
- Loads the recipe configuration
- Finds the downloaded installer of the recorded release
- Inspects the installer: confirms its version against its folder, reads its metadata once, resolves the detection name and architecture, and checks an EXE recipe's required fields, all before anything is written
- Gets/downloads PSADT release
- Creates the build directory, copies PSADT unmodified, generates Invoke-AppDeployToolkit.ps1 from the template, and copies the installer to Files/
- Applies custom branding
- Generates the detection script (used by the App and Update entries)
- Generates the requirements script (when build_types is "both" or "update_only")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Path to the recipe YAML file. |
required |
downloads_dir
|
Path | None
|
Directory containing the downloaded
installer. Default: |
None
|
output_dir
|
Path | None
|
Base directory for build output.
Default: |
None
|
state_dir
|
Path | None
|
State root whose |
None
|
Returns:
| Type | Description |
|---|---|
BuildResult
|
Build result naming the app, the version, the packagefiles directory, and the PSADT version used. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the recipe cannot be loaded or lacks a field the installer type needs, or a configured brand pack path does not exist. |
PackagingError
|
If the installer is missing or does not match the recorded release, its metadata cannot be read, or a build step fails. |
StateError
|
If the deployment state file is corrupted. |
NetworkError
|
If the PSADT release cannot be downloaded. |
Example
Basic build:
result = build_package(Path("recipes/Google/chrome.yaml"))
print(result.build_dir)
# builds/google-chrome/141.0.7390.123/packagefiles
Custom output directory:
Note
Requires installer to be downloaded first (run 'napt discover'). The version is the name of the download folder, checked against the installer's own version for MSI and MSIX. Overwrites existing build directory if it exists. PSADT files are copied unmodified from cache. Invoke-AppDeployToolkit.ps1 is generated (not copied). Scripts are generated as siblings to the packagefiles directory (not included in .intunewin package - must be uploaded separately to Intune). Detection script is always generated. The build_types setting controls requirements script only: "both" (default) generates detection and requirements, "app_only" generates only detection, "update_only" generates detection and requirements.
Source code in napt/build/manager.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
napt.build.installer
The installer a build is made from: finding it and reading it once.
napt build resolves its installer in three steps that all live here: the
release deployment state records, the file in that version's download
folder whose hash matches, and what that file says about itself. The
result is one InstallerInfo that the
rest of the build reads instead of opening the installer again.
InstallerInfo
dataclass
What the build knows about its installer after reading it once.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
The installer file under the downloads directory. |
sha256 |
str
|
Its hex digest, the one recorded at discovery. |
version |
str
|
The version being built, the name of the download folder. |
app_name |
str
|
The display name the detection scripts look for: the MSI
ProductName or MSIX DisplayName, or the recipe's
|
architecture |
ArchitectureMode
|
The registry view the scripts check, read from the
installer for MSI and MSIX and from
|
msi |
MSIMetadata | None
|
The MSI metadata, for an MSI installer. |
msix |
MSIXMetadata | None
|
The MSIX metadata, for an MSIX installer. |
Source code in napt/build/installer.py
release_to_build
Reads the release to build from the app's deployment state.
That is the pending release (awaiting publication), or the published release when nothing is pending, which is the case when rebuilding the current version. Deployment state is committed alongside recipes, so this works on machines that never ran discover, such as a CI publish job restoring downloads from a cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
Recipe configuration. |
required |
state_dir
|
Path | None
|
State root, or None for |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
The release entry ( |
Raises:
| Type | Description |
|---|---|
StateError
|
If the deployment state file exists but is corrupted or has an unsupported schema version. |
Source code in napt/build/installer.py
find_installer_file
find_installer_file(
downloads_dir: Path, app_id: str, release: dict[str, Any] | None
) -> tuple[Path, str]
Finds the installer to build and returns it with its SHA-256.
Discover saves each download to downloads/<id>/<version>/. With a
recorded release, the installer is the file in that version's folder
whose hash matches the recorded one, so a file that was swapped or
corrupted since discovery is refused rather than packaged.
Without a recorded release (a stateless discover and no deployment state), there is nothing to match against, and the single installer found in one of the app's version folders is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
downloads_dir
|
Path
|
Downloads directory to search. |
required |
app_id
|
str
|
Recipe id. |
required |
release
|
dict[str, Any] | None
|
The release to build ( |
required |
Returns:
| Type | Description |
|---|---|
tuple[Path, str]
|
A tuple (installer_path, sha256), where installer_path is the installer file, sha256 is its hex digest. |
Raises:
| Type | Description |
|---|---|
StateError
|
If the recorded version is not a plain folder name. |
PackagingError
|
If no file matches the recorded release, or, with no recorded release, if there is not exactly one installer. |
Source code in napt/build/installer.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
inspect_installer
Reads the installer once and resolves what the build needs from it.
The version is the name of the folder discover filed the installer in
(downloads/<id>/<version>/). An MSI or MSIX reports its own version,
architecture, and name, and discover names the folder after the
version, so the two must agree: a file moved into the wrong folder by
hand would otherwise be built and detected under a version it does not
carry. An EXE carries no usable metadata, so its recipe must supply the
display name, the architecture, and both install commands. Recipe
fields the installer type makes no use of draw one warning each.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer_file
|
Path
|
The installer found by find_installer_file. |
required |
sha256
|
str
|
Its hex digest. |
required |
config
|
dict[str, Any]
|
Recipe configuration. |
required |
Returns:
| Type | Description |
|---|---|
InstallerInfo
|
Everything later build steps read about the installer. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the installer's metadata cannot be read, its version differs from its folder's name, or an MSI has no ProductName. |
ConfigError
|
If an EXE recipe lacks |
Source code in napt/build/installer.py
napt.build.layout
The build folder and what goes into it.
Creates builds/<id>/<version>/packagefiles/, copies the PSADT template
and the installer into it, applies the brand pack, and writes generated
files with a failure reported by path.
write_build_file
Writes a generated build file, reporting a refused write by path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Where to write. |
required |
text
|
str
|
The file's content. |
required |
encoding
|
str
|
Text encoding; generated scripts use
|
required |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the file cannot be written. |
Source code in napt/build/layout.py
create_build_directory
Creates the build directory structure.
Creates {base_dir}/{app_id}/{version}/packagefiles/, replacing an
existing build of that version. The packagefiles/ subdirectory holds
the PSADT files that are packaged into the .intunewin file; detection
scripts are saved as its siblings so they stay out of the package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
Path
|
Base builds directory. |
required |
app_id
|
str
|
Application ID. |
required |
version
|
str
|
Application version. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the packagefiles subdirectory where PSADT files will be copied (build_dir/packagefiles/). |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the version cannot be used as a folder name, or the directory cannot be created. |
Source code in napt/build/layout.py
copy_psadt_template
Copies the PSADT template from the cache into the build unmodified.
Copies the entire v4 template structure: PSAppDeployToolkit/ (module), Invoke-AppDeployToolkit.exe, Invoke-AppDeployToolkit.ps1 (the template, overwritten by the generated script), Assets/, Config/, Strings/, Files/, SupportFiles/, and PSAppDeployToolkit.Extensions/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psadt_cache_dir
|
Path
|
Path to cached PSADT version directory (root of Template_v4 extraction). |
required |
build_dir
|
Path
|
Build directory (packagefiles subdirectory) where PSADT should be copied. |
required |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If PSADT cache directory or required files don't exist, or the copy fails. |
Source code in napt/build/layout.py
copy_installer
Copies the installer to the build's Files/ directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer_file
|
Path
|
Path to the installer file. |
required |
build_dir
|
Path
|
Build directory (packagefiles subdirectory). |
required |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the copy fails. |
Source code in napt/build/layout.py
apply_branding
Replaces PSADT's default assets with the configured brand pack.
Each mapping copies the first file matching its source glob to its
target under the build, keeping the source file's extension. A
mapping whose glob matches nothing leaves the default asset in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
Merged configuration with brand_pack settings. |
required |
build_dir
|
Path
|
Build directory (packagefiles subdirectory) containing PSAppDeployToolkit/. |
required |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the configured |
PackagingError
|
If a brand asset cannot be copied. |
Source code in napt/build/layout.py
napt.build.commands
Install and uninstall commands for the generated deployment script.
MSI and MSIX installers carry enough metadata to generate both commands;
the recipe's own psadt.install and psadt.uninstall are used only
when the matching override flag is set. EXE recipes always supply their
own, so there is nothing to generate for them.
apply_install_commands
Sets the install and uninstall commands the deployment script runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
Recipe configuration, mutated in place for MSI and MSIX. |
required |
installer
|
InstallerInfo
|
The inspected installer. |
required |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If an override flag is set without a command to use. |
PackagingError
|
If an MSI has no ProductName to uninstall by. |
Source code in napt/build/commands.py
napt.build.scripts
The detection and requirements scripts written beside a build.
Both scripts are named after the app and version and saved as siblings of
the packagefiles/ folder, so they stay out of the .intunewin file and
napt upload can send them to Intune separately. MSIX installers get
the AppX package queries; MSI and EXE installers get the registry scripts.
sanitize_filename
Makes an app name safe to use in a Windows filename.
Spaces become hyphens, the characters Windows forbids (< > : " | ? * \ /) are dropped, runs of hyphens collapse, and leading or trailing hyphens and dots are trimmed. A name with nothing left falls back to the app id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
String to sanitize (e.g., "Google Chrome"). |
required |
app_id
|
str
|
Fallback when nothing usable is left. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Sanitized filename-safe string (e.g., "Google-Chrome"). |
Example
Basic sanitization:
Source code in napt/build/scripts.py
write_detection_script
Writes the detection script Intune runs to see whether the app is installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer
|
InstallerInfo
|
The inspected installer. |
required |
config
|
dict[str, Any]
|
Recipe configuration. |
required |
build_dir
|
Path
|
Build directory (packagefiles subdirectory). |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the generated detection script. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the script cannot be written. |
Source code in napt/build/scripts.py
write_requirements_script
write_requirements_script(
installer: InstallerInfo, config: dict[str, Any], build_dir: Path
) -> Path
Writes the requirements script that scopes the update entry to older installs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
installer
|
InstallerInfo
|
The inspected installer. |
required |
config
|
dict[str, Any]
|
Recipe configuration. |
required |
build_dir
|
Path
|
Build directory (packagefiles subdirectory). |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the generated requirements script. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the script cannot be written. |
Source code in napt/build/scripts.py
napt.build.manifest
The build manifest: what a build records about itself for later stages.
napt build writes build-manifest.json beside packagefiles/.
napt package reads it to verify the build and copies it into the
package folder with the .intunewin name and hash added; napt upload
reads that copy. The key names live here so every stage spells them the
same way.
write_build_manifest
write_build_manifest(
build_dir: Path,
app_id: str,
app_name: str,
version: str,
build_types: str,
architecture: str,
installer_sha256: str,
detection_script_path: Path,
requirements_script_path: Path | None,
) -> Path
Writes the build manifest beside the packagefiles folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
build_dir
|
Path
|
Build directory (packagefiles subdirectory). |
required |
app_id
|
str
|
Application ID. |
required |
app_name
|
str
|
Application display name. |
required |
version
|
str
|
Application version. |
required |
build_types
|
str
|
The build_types setting used ("both", "app_only", "update_only"). |
required |
architecture
|
str
|
Resolved installer architecture ("x86", "x64", "arm64", "any"): from the installer for MSI and MSIX, from the recipe for EXE. |
required |
installer_sha256
|
str
|
SHA-256 hex digest of the source installer file, carried through so 'napt upload' can verify provenance. |
required |
detection_script_path
|
Path
|
The detection script. |
required |
requirements_script_path
|
Path | None
|
The requirements script, or None when build_types is "app_only". |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written manifest. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the manifest cannot be written. |
Source code in napt/build/manifest.py
read_build_manifest
Reads a build manifest and checks the keys the caller relies on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
The folder holding |
required |
required
|
tuple[str, ...]
|
Keys that must be present as non-empty strings. |
required |
remedy
|
str
|
What to run to get a good manifest, appended to every error message. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The parsed manifest. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the manifest is missing, not JSON, not an object, or lacks a required key. |