Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PowerShell cmdlets #2838

Merged
merged 11 commits into from
Mar 21, 2023
Merged

Conversation

msftrubengu
Copy link
Contributor

@msftrubengu msftrubengu commented Jan 11, 2023

This PR implements two new PowerShelll cmdlets Assert-WinGetPackageManager and Repair-WinGetPackageManager as well as the WinGetPackageManager DSC Resource.

Assert-WinGetPackageManager verifies the integrity of winget for the current user. If winget is not set up correctly, it will throw an exception with the type of failure if detected.
It can detect:

  • Failed call into winget --version.
  • winget is not found because is not in the PATH environment variable.
  • winget is not found because the App execution alias is disabled.
  • Windows OS is not supported.
  • The AppInstaller package is not installed in the machine.
  • The AppInstaller package is not registered for the user.
  • The AppInstaller package is old and doesn't contain winget.

Assert-WinGetPackageManager -Version foo also verifies the installed version is the same as the expected.
Assert-WinGetPackageManager -Latest also verifies the installed version is the latest release version.
Assert-WinGetPackageManager -Latest -IncludePrerelease also verifies the installed version is the latest prerelease version.

Repair-WinGetPackageManager does the same as Assert-WinGetIntegrity but attempts to fix winget depending on the failure. Returns 0 is succeeded.

Repair-WinGetPackageManager repairs current winget installed and performs no updates. If winget is not installed or there's catastrophic failure then installs the latest released winget.
Repair-WinGetPackageManager -Version foo repairs winget and makes sure that the current installed version is the expected one.
Repair-WinGetPackageManager -Latest repairs winget and makes sure winget is the latest released version.
Repair-WinGetPackageManager -Latest -IncludePreRelease repairs winget and makes sure winget is the latest prereleased version.

It sadly can't repair if AppExecution alias is disabled because there's no programmatic way to do it (requires internal APIs).

It also doesn't install Microsoft.UI.Xaml.2.7 as a dependency because the current solution to download the nuget package, extract it and install the appx within is not the right approach we want to follow. We will follow up internally with the owners of the package to do something similar as the VCLibs packages.

There's still a lot of opportunity for Repair-WinGetPackageManager to make it more robust, but this PR is just the starting phase.

The WinGetPackageManager DSC resource is just a simple wrapper around those two cmdlets. There's also a sample on how to use it.

For now, all versions need to be the tag name of the releases in GitHub.

Also, moved Get-WinGetVersion from Crescendo to a binary cmdlet.

Microsoft Reviewers: Open in CodeFlow

@msftrubengu msftrubengu requested a review from a team as a code owner January 11, 2023 04:04
@github-actions

This comment has been minimized.

private void InstallUiXaml()
{
// TODO: We need to follow up for Microsoft.UI.Xaml.2.7
// downloading the nuget and extracting it doesn't sound like the right thing to do.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UI.Xaml package is one of the bigger sticking points for installing winget on devices that don't have access to the store. I think that even though it isn't the proper long-term approach, using the workaround through nuget temporarily would provide a better user experience

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should implement that before fully releasing this, but I don't think it should necessarily block this PR.

toInstallVersion = gitHubRelease.GetLatestVersionTagName(preRelease);
}

if (toInstallVersion != WinGetVersionHelper.InstalledWinGetVersion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see implied wildcarding for version matching. For example - If the user specified -Version 1.3 or -Version 1.3.2 it would map to the version tag 1.3.2691. But if they used -Version 1.3.1 it would map to the version tag 1.3.1872 and require the -Prerelease switch. Whereas -Version 1.3.20 would map to 1.3.2091.

This follows the idea that the cli version is often referenced as the "1.3 Client" or the "1.4 Client", so it's very common to only use the prefix of the version number.

(Yes, I know, I'm asking for scope creep here; Sorry @denelon)

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Member

@JohnMcPMS JohnMcPMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a minimum the ARM64 change and the string change are needed. If we could do the UI XAML code easily, then I suspect you would have done it. But maybe you didn't investigate how difficult it would be to implement?

private void InstallUiXaml()
{
// TODO: We need to follow up for Microsoft.UI.Xaml.2.7
// downloading the nuget and extracting it doesn't sound like the right thing to do.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should implement that before fully releasing this, but I don't think it should necessarily block this PR.

@msftrubengu
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@msftrubengu msftrubengu merged commit fc215c4 into microsoft:master Mar 21, 2023
@msftrubengu msftrubengu deleted the wingetintegrity branch April 7, 2023 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants