Copilot instructions
.github/instructions/start-native-execution.instructions.mdCopilot instructions
Quality
86/100
Scores the file, not the repository.Length
434 words
18 headings · 12 code blocksRepository
55k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1234567# Using Start-NativeExecution for Native Command Execution89## Purpose1011`Start-NativeExecution` is the standard function for executing native commands (external executables) in PowerShell scripts within this repository. It provides consistent error handling and better diagnostics when native commands fail.1213## When to Use1415Use `Start-NativeExecution` whenever you need to:16- Execute external commands (e.g., `git`, `dotnet`, `pkgbuild`, `productbuild`, `fpm`, `rpmbuild`)17- Ensure proper exit code checking18- Get better error messages with caller information19- Handle verbose output on error2021## Basic Usage2223```powershell24Start-NativeExecution {25 git clone https://github.com/PowerShell/PowerShell.git26}27```2829## With Parameters3031Use backticks for line continuation within the script block:3233```powershell34Start-NativeExecution {35 pkgbuild --root $pkgRoot `36 --identifier $pkgIdentifier `37 --version $Version `38 --scripts $scriptsDir `39 $outputPath40}41```4243## Common Parameters4445### -VerboseOutputOnError4647Captures command output and displays it only if the command fails:4849```powershell50Start-NativeExecution -VerboseOutputOnError {51 dotnet build --configuration Release52}53```5455### -IgnoreExitcode5657Allows the command to fail without throwing an exception:5859```powershell60Start-NativeExecution -IgnoreExitcode {61 git diff --exit-code # Returns 1 if differences exist62}63```6465## Availability6667The function is defined in `tools/buildCommon/startNativeExecution.ps1` and is available in:68- `build.psm1` (dot-sourced automatically)69- `tools/packaging/packaging.psm1` (dot-sourced automatically)70- Test modules that include `HelpersCommon.psm1`7172To use in other scripts, dot-source the function:7374```powershell75. "$PSScriptRoot/../buildCommon/startNativeExecution.ps1"76```7778## Error Handling7980When a native command fails (non-zero exit code), `Start-NativeExecution`:811. Captures the exit code822. Identifies the calling location (file and line number)833. Throws a descriptive error with full context8485Example error message:86```87Execution of {git clone ...} by /path/to/script.ps1: line 42 failed with exit code 188```8990## Examples from the Codebase9192### Git Operations93```powershell94Start-NativeExecution {95 git fetch --tags --quiet upstream96}97```9899### Build Operations100```powershell101Start-NativeExecution -VerboseOutputOnError {102 dotnet publish --configuration Release103}104```105106### Packaging Operations107```powershell108Start-NativeExecution -VerboseOutputOnError {109 pkgbuild --root $pkgRoot --identifier $pkgId --version $version $outputPath110}111```112113### Permission Changes114```powershell115Start-NativeExecution {116 find $staging -type d | xargs chmod 755117 find $staging -type f | xargs chmod 644118}119```120121## Anti-Patterns122123**Don't do this:**124```powershell125& somecommand $args126if ($LASTEXITCODE -ne 0) {127 throw "Command failed"128}129```130131**Do this instead:**132```powershell133Start-NativeExecution {134 somecommand $args135}136```137138## Best Practices1391401. **Always use Start-NativeExecution** for native commands to ensure consistent error handling1412. **Use -VerboseOutputOnError** for commands with useful diagnostic output1423. **Use backticks for readability** when commands have multiple arguments1434. **Don't capture output unnecessarily** - let the function handle it1445. **Use -IgnoreExitcode sparingly** - only when non-zero exit codes are expected and acceptable145146## Related Documentation147148- Source: `tools/buildCommon/startNativeExecution.ps1`149- Blog post: https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right/150
Also in PowerShell/PowerShell
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| PowerShell/PowerShell.github/instructions/code-review-branch-strategy.instructions.md · 55k | Copilot instructions | lint-formatstyletypesgit+1 | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/instruction-file-format.instructions.md · 55k | Copilot instructions | buildlint-formatstylearch+3 | 76/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/pester-set-itresult-pattern.instructions.md · 55k | Copilot instructions | setupstylearch | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/powershell-automatic-variables.instructions.md · 55k | Copilot instructions | stylearchgitdeployment+1 | 69/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/pester-test-status-and-working-meaning.instructions.md · 55k | Copilot instructions | teststyle | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/build-and-packaging-steps.instructions.md · 55k | Copilot instructions | buildagent-behaviour | 58/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/build-checkout-prerequisites.instructions.md · 55k | Copilot instructions | setupbuildstylearch+1 | 81/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/build-configuration-guide.instructions.md · 55k | Copilot instructions | buildteststyletesting-strategy+2 | 74/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/log-grouping-guidelines.instructions.md · 55k | Copilot instructions | buildtestdo-not | 77/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/onebranch-condition-syntax.instructions.md · 55k | Copilot instructions | buildstylearchdeployment+1 | 73/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/onebranch-restore-phase-pattern.instructions.md · 55k | Copilot instructions | arch | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/onebranch-signing-configuration.instructions.md · 55k | Copilot instructions | buildstyledeployment | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/powershell-module-organization.instructions.md · 55k | Copilot instructions | buildteststylearch+2 | 69/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/powershell-parameter-naming.instructions.md · 55k | Copilot instructions | styledo-not | 65/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/publishing-pester-result.instructions.md · 55k | Copilot instructions | testlint-formatstylearch+3 | 69/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/script-module-file-format.instructions.md · 55k | Copilot instructions | lint-format | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/start-psbuild-basics.instructions.md · 55k | Copilot instructions | buildtesting-strategydeploymentagent-behaviour | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/troubleshooting-builds.instructions.md · 55k | Copilot instructions | buildgitdeployment | 54/100 | 3 days ago |
Diff against .github/instructions/code-review-branch-strategy.instructions.md Diff against .github/instructions/instruction-file-format.instructions.md Diff against .github/instructions/pester-set-itresult-pattern.instructions.md Diff against .github/instructions/powershell-automatic-variables.instructions.md Diff against .github/instructions/pester-test-status-and-working-meaning.instructions.md Diff against .github/instructions/build-and-packaging-steps.instructions.md Diff against .github/instructions/build-checkout-prerequisites.instructions.md Diff against .github/instructions/build-configuration-guide.instructions.md Diff against .github/instructions/log-grouping-guidelines.instructions.md Diff against .github/instructions/onebranch-condition-syntax.instructions.md Diff against .github/instructions/onebranch-restore-phase-pattern.instructions.md Diff against .github/instructions/onebranch-signing-configuration.instructions.md Diff against .github/instructions/powershell-module-organization.instructions.md Diff against .github/instructions/powershell-parameter-naming.instructions.md Diff against .github/instructions/publishing-pester-result.instructions.md Diff against .github/instructions/script-module-file-format.instructions.md Diff against .github/instructions/start-psbuild-basics.instructions.md Diff against .github/instructions/troubleshooting-builds.instructions.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 3 days ago | |
| louislam/uptime-kuma.github/copilot-instructions.md · 90k | Copilot instructions | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| pytorch/pytorch.github/copilot-instructions.md · 102k | Copilot instructions | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| dotnet/roslyn.github/instructions/Compiler.instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 99/100 | 3 days ago | |
| JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 31k | Copilot instructions | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| hiyouga/LlamaFactory.github/copilot-instructions.md · 74k | Copilot instructions | setupbuildtestlint-format+5 | 97/100 | 2 days ago | |
| rtk-ai/rtk.github/copilot-instructions.md · 75k | Copilot instructions | buildtestlint-formatstyle+2 | 97/100 | 3 days ago | |
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 97/100 | 3 days ago |
