{"record":{"id":"ba5ca672e50ae35d","repo":"dotnet/maui","slug":"powershell-core-pwsh-is-required-on-non-windows","errorCode":null,"errorMessage":"PowerShell Core (pwsh) is required on non-Windows platforms. Please install it and try again.","messagePattern":"PowerShell Core \\(pwsh\\) is required on non-Windows platforms\\. Please install it and try again\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"eng/cake/dotnet.cake","lineNumber":606,"sourceCode":"        }\n        else\n        {\n            var exitCode = StartProcess(\"which\", new ProcessSettings\n            {\n                Arguments = \"pwsh\",\n                RedirectStandardOutput = true,\n                RedirectStandardError = true\n            });\n            if (exitCode != 0)\n            {\n                throw new Exception(\"PowerShell Core (pwsh) is not installed. Please install it to continue.\");\n            }\n        }\n    }\n    catch (Exception ex) when (!IsRunningOnWindows())\n    {\n        Error(\"Error checking for pwsh: \" + ex.Message);\n        throw new Exception(\"PowerShell Core (pwsh) is required on non-Windows platforms. Please install it and try again.\");\n    }\n\n    // Execute the PowerShell script\n    StartProcess(pwshExecutable, new ProcessSettings\n    {\n        Arguments = \"-NonInteractive -ExecutionPolicy Bypass -File ./eng/scripts/update-cgmanifest.ps1\"\n    });\n});\n\nTask(\"publicapi\")\n    .Description(\"Clears PublicAPI.Unshipped.txt files and regenerates them with current public APIs. Processes Core, Controls, Essentials, and Graphics projects. Skips Windows files on non-Windows platforms and always skips Tizen files. Use after adding new public APIs to resolve build errors.\")\n    .Does(() =>\n{\n    var corePublicApiDir = MakeAbsolute(Directory(\"./src/Core/src/PublicAPI\"));\n    var controlsPublicApiDir = MakeAbsolute(Directory(\"./src/Controls/src/Core/PublicAPI\"));\n    var essentialsPublicApiDir = MakeAbsolute(Directory(\"./src/Essentials/src/PublicAPI\"));\n    var graphicsPublicApiDir = MakeAbsolute(Directory(\"./src/Graphics/src/Graphics/PublicAPI\"));\n","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/eng/cake/dotnet.cake#L588-L624","documentation":"Re-thrown on non-Windows platforms when any exception escapes the pwsh-availability check (the `catch (Exception ex) when (!IsRunningOnWindows())` filter). It wraps the original exception's message in an Error log and throws a clearer 'pwsh is required on non-Windows' message, since the cgmanifest update script is PowerShell-based and cannot run without pwsh.","triggerScenarios":"Any exception inside the pwsh-detection try block (not just the `which` failure) while running on Linux/macOS. For example, StartProcess itself throwing, or the Windows-specific lookup path erroring when intercepted by the non-Windows filter.","commonSituations":"Same root causes as the pwsh-not-installed error but surfaced through the catch-all: a malformed PATH, a permission error invoking `which`, or a partial pwsh install. The non-Windows guard converts these into a single actionable message.","solutions":["Install PowerShell Core on the non-Windows host (apt/brew) and confirm `pwsh --version` works.","Check the preceding 'Error checking for pwsh: <message>' log line for the original exception detail.","Ensure the user running cake has execute permission on the pwsh binary and that PATH includes its directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate platform + pwsh up front on non-Windows\nif (!IsRunningOnWindows()) {\n    var exitCode = StartProcess(\"which\", new ProcessSettings { Arguments = \"pwsh\", RedirectStandardOutput = true });\n    if (exitCode != 0)\n        throw new Exception(\"Install PowerShell Core (pwsh) before running this task on Linux/macOS.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bake pwsh into non-Windows CI images.","Surface the original exception message (ex.Message) in the re-throw so root cause is visible.","Narrow the catch filter to specific expected exceptions rather than catching all and re-wrapping."],"tags":["pwsh","powershell","non-windows","environment","dependency"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}