Commit 99821c1
authored
Make Repair-WGPM a COM-aware cmdlet and rework version retrieval (CP to 1.12) (#5858)
CP of #5842
## Issue
A previous change introduced a COM API to retrieve the WinGet version.
The PowerShell methods to get the version were updated to try using it
before invoking the existing method (run `winget --version`).
This caused Repair-WGPM to use COM for the first time (IFF a version
specifier was provided [which includes `-Latest`]). This caused the two
linked issues:
1. #5826 :: In .NET Framework (Windows PowerShell), the .winmd file must
be found in order to generate the COM type information at runtime. This
is required when jit'ing the new version API, used only when a version
specifier is provided. This doesn't affect .NET Core (PowerShell 7)
because exceptions are swallowed to support backward compat and the
types are all pre-generated by CsWinRT. Only commands deriving from a
specific type were doing the initialization required.
2. #5827 :: Calling a COM API means that the server is active, making
attempts to install the package fail due to an in-use error. This
required `-Force` to be provided, again only if a version specifier was
provided.
## Change
The larger part of this change reworks the existing assert and repair
state machine to better re-use the call to `winget --version` that is
actually attempting to probe for WinGet CLI functionality. We keep that
result around and use it when comparing to the supplied target version
rather than attempting to retrieve the version again. If the version is
not correct, we attach it to the exception that is thrown so that we can
re-use it once again during the attempt to install the different
version.
Since the first attempt to call `winget --version` has to succeed in
order to get to the code that would check the current version, we can
successfully avoid the COM call in this path every time. Ultimately this
means that if WinGet is already installed properly, attempting to change
the version with Repair only gets the version once instead of the
previous 3 times.
The final portion of the change updates the base command for Repair and
Assert to the one that provides the COM initialization. While this
shouldn't be necessary with the other portion, it is preferable to
supply `-Force` as a workaround than to simply wait for a resolution if
the type cannot be loaded.1 parent 95add98 commit 99821c1
File tree
4 files changed
+46
-18
lines changed- src/PowerShell/Microsoft.WinGet.Client.Engine
- Commands
- Common
- Exceptions
- Helpers
4 files changed
+46
-18
lines changedLines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
173 | 177 | | |
174 | 178 | | |
175 | 179 | | |
| |||
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
| 80 | + | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
56 | 62 | | |
57 | 63 | | |
58 | 64 | | |
| |||
Lines changed: 24 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
67 | 79 | | |
68 | 80 | | |
69 | 81 | | |
70 | 82 | | |
| 83 | + | |
71 | 84 | | |
72 | | - | |
| 85 | + | |
73 | 86 | | |
74 | | - | |
75 | | - | |
76 | | - | |
| 87 | + | |
77 | 88 | | |
78 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
79 | 97 | | |
80 | 98 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 99 | + | |
84 | 100 | | |
85 | 101 | | |
86 | 102 | | |
| |||
0 commit comments