winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

Enable winget to upgrade itself

Open JohnMcPMS opened this issue 5 years ago • 7 comments

Description of the new feature/enhancement

Winget cannot update it's own package currently, due to the following sequence:

  1. winget begins deployment of its package
  2. Windows deployment for MSIX needs all processes for the package to be shut down
  3. Deployment sends a CTRL-C message to processes with no active windows
  4. winget responds to CTRL-C message with cancellation of the deployment operation

So a whole lot of nothing happens.

Proposed technical implementation details

The most straightforward way is probably to special case this scenario. We could also do some work to run afterward to report the result. For instance (install or update eventually):

winget install winget
... all boilerplate until install progress ...
winget needs to terminate in order to update itself, see you in a bit.

Once completed, a new (cmd, unless you can somehow set the default subsystem CONSOLE handler) window comes up to automatically run:

winget post-self-update
Success, winget has been updated to v0.1.99999
Press enter to close this window

or

winget post-self-update
winget update failed: Some perfectly valid reason I'm sure.
winget is still running v0.1.12345
Press enter to close this window

JohnMcPMS avatar Jul 20 '20 19:07 JohnMcPMS

Given that winget will be part of the App Installer bundle, pre-installed and updated over the Windows Store AND that winget also plans support for Windows Store applications... is this issue in the current form still relevant?

Croydon avatar Jul 07 '21 18:07 Croydon

@Croydon, there are several different scenarios at play when we take into account enterprise Group Policy, and private sources. Some systems may have the Microsoft Store disabled, and they may be on their own private networks. It would still be possible to pull in a copy of the App Installer and provide it via a private REST source.

denelon avatar Jul 12 '21 22:07 denelon

When winget is available as a built in then "winget upgrade winget" should switch me over from the manually installed appxbundle to the officially supported version from windows.

lovettchris avatar Jul 16 '21 20:07 lovettchris

@lovettchris you should automatically get updates from the Microsoft Store since the releases here are signed. The store would only hand you the "latest" version available for the environment (Windows Insider) or Flight (Partner Center Concept). Once a newer version is published, you would get that update to App Installer.

The ability to use the Windows Package Manager to upgrade itself is not necessary to receive the latest stable version from the Microsoft Store. The only requirement is the version in the store must be higher than the version one has installed.

denelon avatar Jul 16 '21 22:07 denelon

It is now possible to use the Windows Package Manager to install via the "msstore" source.

winget install "App Installer" -s msstore --force

edited: I added "--force" as this is required in some scenarios.

We still have work with the "msstore" source to report the version in the REST endpoint. We also have work to include monikers in the "msstore" source so the command could be winget install winget -s msstore.

denelon avatar Feb 17 '22 18:02 denelon

@denelon could you explain it a bit for an "end-user": is it correct that:

  1. winget install "App Installer" -s msstore supposed to update App Installer
  2. winget is a part of App Installer
  3. hence winget install "App Installer" -s msstore is supposed to update winget ..in certain case

?

What are those cases and is it safe to just try winget install "App Installer" -s msstore and see what happens?

YakovL avatar Feb 18 '22 12:02 YakovL

@YakovL

  1. Technically it's just asking the Windows Package Manager to install the App Installer.
  2. The Windows Package Manager is distributed with the App Installer.
  3. True

The install command today does not perform validation if a package is already installed. We're likely to start checking to see if a package is already installed so a user can get the correct upgrade behavior for packages that require certain switches to be passed to the installer for the upgrade scenario to function correctly (Visual Studio is an example of this). In the future, we may add a repair option for MSIX packages, and with the switch to the "upgrade" behavior, you could still pass "--force" to insist the Windows Package Manager perform the install action "winget install "App Installer" -s msstore --force`.

Yes, you are likely to be prompted about which version of App Installer you are attempting to install, and you will be informed if the version you are about to install is "older" than the one present on your system.

denelon avatar Feb 18 '22 15:02 denelon

Does this work? because I tried and winget just spins on "Starting package install..." forever.

winget v1.3.2691 windows 21h2

santagada avatar Feb 15 '23 13:02 santagada

@santagada is a bad user experience, but yes it will work.

Depending on the version difference, I've seen it hang in the progress bar, and I've seen it throw an exception. Generally, if I wait a few seconds after that point, I can either [ctrl]+[c] or restart my terminal and run winget -v to see if the new version is installed.

denelon avatar Feb 15 '23 16:02 denelon

winget install winget --accept-source-agreements --accept-package-agreements --force

winget -v v1.4.10173

winget upgrade -all winget upgrade -all -silent

hariomsai7 avatar Mar 31 '23 06:03 hariomsai7

Having to kill the application after a while is really bad for automation. Winget is supposed to be used for automation right? I ask because not having it on server versions kinda confuses me a bit.

santagada avatar Mar 31 '23 06:03 santagada

There are very few things you can do when you are trying to use the tool....to update the thing you are using. Especially since this is a package and not a traditional app

Masamune3210 avatar Mar 31 '23 18:03 Masamune3210

I found a better way to resolve this, install scoop first, then use scoop to install/update winget. As winget is just an installer, not a package manager.

ArchGuyWu avatar Sep 04 '23 05:09 ArchGuyWu

The App Installer was just added to the community repository so you can now run winget upgrade winget.

denelon avatar Dec 05 '23 23:12 denelon

The App Installer was just added to the community repository so you can now run winget upgrade winget.

But the previous version cannot be removed, because it's a part of windows.

ArchGuyWu avatar Dec 06 '23 05:12 ArchGuyWu

tried winget upgrade winget, got ~"No available updates found. No more recent versions in the configured sources." (translated back to English, so the wording may be not accurate) winget -v → v1.6.3133

YakovL avatar Dec 06 '23 06:12 YakovL

The App Installer was just added to the community repository so you can now run winget upgrade winget.

But the previous version cannot be removed, because it's a part of windows.

Yes.....your point is? There isn't any way around that, it happens no matter how you update winget or any in-box app. Its just how Windows handles it.

Masamune3210 avatar Dec 06 '23 22:12 Masamune3210