microsoft / microsoft/winget-pkgs

[New Feature]: YamlCreate.ps1 should work with PowerShell StrictMode

Open
#261,810 3 comments 0 reactions 0 assignees View on GitHub
Issue-Feature
Dominant language
No language data
Stars
11.1k
Forks
9.7k
PR merge metrics
PR metrics pending

Description

### Description of the new feature/enhancement

PowerShell "Strict Mode" is a way to have PowerShell help you write better scripts, by complaining when your scripts violate best-practice coding rules. It helps you find bugs you may not even realize you had. See: [Set-StrictMode](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode?view=powershell-7.5). According to Strict Mode, `YamlCreate.ps1` could use some improvement.

In addition to just making `YamlCreate.ps1` better, this means it won't fail for zealots like me, who set `Set-StrictMode -Version Latest` in their `$profile` script. :D

## Repro steps:
1. `Set-StrictMode -Version Latest`
2. `.\Tools\YamlCreate.ps1`

## Expected Result:
It all just works, and looks good doing it.

## Actual result:
TONS of red error spew:

```
PS C:\src\winget-pkgs> .\Tools\YamlCreate.ps1
Install-PackageProvider: C:\src\winget-pkgs\Tools\YamlCreate.ps1:165
Line |
165 | Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Fo …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Administrator rights are required to install packages in 'C:\Program Files\PackageManagement\ProviderAssemblies'. Log on to the computer with an
| account that has Administrator rights, and then try again, or install in 'C:\Users\danthom\AppData\Local\PackageManagement\ProviderAssemblies' by
| adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
PropertyNotFoundException: C:\src\winget-pkgs\Tools\YamlCreate.ps1:207
Line |
207 | $_wingetVersion = 1.0.0
| ~~~~~~~~~~~~~~~~~~~~~~~
| The property '0' cannot be found on this object. Verify that the property exists.
PropertyNotFoundException: C:\src\winget-pkgs\Tools\YamlCreate.ps1:212
Line |
212 | if ($ScriptSettings.EnableDeveloperOptions -eq $true -and $null -ne $ …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The property 'EnableDeveloperOptions' cannot be found on this object. Verify that the property exists.
PropertyNotFoundException: C:\src\winget-pkgs\Tools\YamlCreate.ps1:2623
Line |
2623 | $script:UsingAdvancedOption = ($ScriptSettings.EnableDeveloperOptions …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The property 'EnableDeveloperOptions' cannot be found on this object. Verify that the property exists.
InvalidOperation: C:\src\winget-pkgs\Tools\YamlCreate.ps1:2625
Line |
2625 | if (!$script:UsingAdvancedOption) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The variable '$script:UsingAdvancedOption' cannot be retrieved because it has not been set.
InvalidOperation: C:\src\winget-pkgs\Tools\YamlCreate.ps1:2680
Line |
2680 | if (($script:Option -eq 'QuickUpdateVersion') -and ($ScriptSettings.S …
| ~~~~~~~~~~~~~~
| The variable '$script:Option' cannot be retrieved because it has not been set.

InvalidOperation: C:\src\winget-pkgs\Tools\YamlCreate.ps1:2699
Line |
2699 | if (($script:Option -eq 'MovePackageIdentifier')) {
| ~~~~~~~~~~~~~~
| The variable '$script:Option' cannot be retrieved because it has not been set.

[Required] Enter the Package Identifier, in the following format . For example: Microsoft.Excel
PackageIdentifier:
```

### Proposed technical implementation details (optional)

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with Tools/YamlCreate.ps1 and reproduce the reported failures after running Set-StrictMode -Version Latest. Trace the errors at the listed lines, then rerun the script to confirm it completes without StrictMode errors and reaches its normal prompt.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.