Repository: microsoft/terminal (language: cpp)

Issue:
Can't install Terminal 1.12.10732.0 using DISM on Windows 11
### Windows Terminal version

1.12.10732.0

### Windows build number

10.0.22000.556

### Other Software

_No response_

### Steps to reproduce

```cmd
SET WINTERMVERSION=1.12.10732.0
curl -Lo terminal-preinstall.zip https://github.com/microsoft/terminal/releases/download/v%WINTERMVERSION%/Microsoft.WindowsTerminal_Win10_%WINTERMVERSION%_8wekyb3d8bbwe.msixbundle_Windows10_PreinstallKit.zip
MKDIR term
tar -C term -xvf terminal-preinstall.zip
FOR %%i IN (term\*.msixbundle) DO SET MSIX=%%i
FOR %%i IN (term\*_License1.xml) DO SET LIC=%%i
DISM /Online /Add-ProvisionedAppxPackage /PackagePath:%MSIX% /LicensePath:%LIC%
```

### Expected Behavior

Installs the updated version, as it did with `WINTERMVERSION=1.11.3471.0` (without the extra `_Win10_` before the version in the download filename)

### Actual Behavior

```
2022-04-03 20:07:28, Error                 DISM   DISM Appx Provider: PID=1452 TID=7716 onecore\admin\appmodel\utilities\provisionhelper\msixprovisioningrequest.cpp(878)\AppxProvider.dll!00007FFC98D761A4: (caller: 00007FFC98D74734) ReturnHr(1) tid(1e24) C1570118     Msg:[Failed while adding package Microsoft.WindowsTerminal_1.12.10732.0_neutral_~_8wekyb3d8bbwe since an equal or higher version of the package, Microsoft.WindowsTerminal_2021.226.1915.0_neutral_~_8wekyb3d8bbwe, already exists] 
 - CAppxManager::ResultLoggingCallback
2022-04-03 20:07:28, Error                 DISM   DISM Appx Provider: PID=1452 TID=7716 onecore\admin\appmodel\utilities\provisionhelper\msixprovisioningrequest.cpp(180)\AppxProvider.dll!00007FFC98D74790: (caller: 00007FFC98D73F54) ReturnHr(2) tid(1e24) C1570118     Msg:[Failed to remove existing package version for 'Microsoft.WindowsTerminal_1.12.10732.0_neutral_~_8wekyb3d8bbwe'.] 
 - CAppxManager::ResultLoggingCallback
2022-04-03 20:07:28, Error                 DISM   DISM Appx Provider: PID=1452 TID=7716 onecore\admin\appmodel\utilities\provisionhelper\msixprovisioningrequest.cpp(79)\AppxProvider.dll!00007FFC98D743F4: (caller: 00007FFC98D7FF70) ReturnHr(3) tid(1e24) C1570118     Msg:[Failed to add main bundle package for provisioning.] 
 - CAppxManager::ResultLoggingCallback
2022-04-03 20:07:28, Error                 DISM   DISM Appx Provider: PID=1452 TID=7716 onecore\admin\appmodel\utilities\provisionhelper\msixpackageadapter.cpp(1439)\AppxProvider.dll!00007FFC98D7FFA0: (caller: 00007FFC98D75A10) ReturnHr(4) tid(1e24) C1570118     Msg:[Failed to initialize package adapter.] 
 - CAppxManager::ResultLoggingCallback
2022-04-03 20:07:28, Error                 DISM   DISM Appx Provider: PID=1452 TID=7716 onecore\admin\appmodel\utilities\provisionhelper\msixprovisioningrequest.cpp(651)\AppxProvider.dll!00007FFC98D75B54: (caller: 00007FFC98D7A0B4) ReturnHr(5) tid(1e24) C1570118     Msg:[Failed to create adapter for 'term\a372015b7dfd43638e7e21f052c12151.msixbundle'.] 
 - CAppxManager::ResultLoggingCallback
2022-04-03 20:07:28, Error                 DISM   DISM Appx Provider: PID=1452 TID=7716 onecore\admin\appmodel\utilities\provisionhelper\msixprovisioningmanager.cpp(920)\AppxProvider.dll!00007FFC98D7A0E8: (caller: 00007FFC98D4A2B8) ReturnHr(6) tid(1e24) C1570118     Msg:[Failed to add package 'term\a372015b7dfd43638e7e21f052c12151.msixbundle' to adapter set for processing.] 
 - CAppxManager::ResultLoggingCallback
```


Discussion / hints:
Interesting part of error message:
`
Failed while adding package Microsoft.WindowsTerminal_1.12.10732.0_neutral_~_8wekyb3d8bbwe since an equal or higher version of the package, Microsoft.WindowsTerminal_2021.226.1915.0_neutral_~_8wekyb3d8bbwe, already exists
`

At first I thought I needed to manually specify the new dependency packages to the DISM command, but it doesn't seem to be getting that far.  Also, now that I see that, I wonder if that's why I haven't seen a store update for 1.12 yet on any of my machines...

Hey look, an external report of this one! We're actually working through this right now. Weirdly, #12779 should have helped, we're gonna publish another package soon to validate. 
To be clear, unlike #12779 this is not trying to reinstall the *same* version that's already installed.  I am trying to upgrade the version that comes pre-installed in Windows 11 using the PreInstall kit for 12.0.10732.0.
If I had to guess, this is another way in which MSIX has screwed us up. I was worried about this.

When we build Terminal, we produce an msixbundle. That bundle has its own separate version number (yeah, wtf?)... or, at least, it _did_. It defaulted to `YYYY.MM.DD.0` or something similar.

We fixed this in #12691... which pins the bundle version to be the same as the Terminal version that it contains.

I was gravely worried about the fact that major version `1` is much less than major version `2021`... but I tried upgrading on both Windows 10 and Windows 11 and verified that _this isn't actually a problem._

Except, the app platform is entirely inscrutable. Things that are not a problem on one machine (or four, in my case) are _significant_ problems on other folks' machines.

I suspect this is the same root cause as https://github.com/microsoft/terminal/discussions/12761#discussioncomment-2441723.

Fix patch:
diff --git a/build/pipelines/release.yml b/build/pipelines/release.yml
index 301e8709b6f..5b704b5e398 100644
--- a/build/pipelines/release.yml
+++ b/build/pipelines/release.yml
@@ -321,11 +321,16 @@ jobs:
         displayName: Download Artifacts ${{ platform }} $(TerminalTargetWindowsVersion)
         inputs:
           artifactName: appx-${{ platform }}-Release-$(TerminalTargetWindowsVersion)
-    - task: PowerShell@2
+    # Add 3000 to the major version component, but only for the bundle.
+    # This is to ensure that it is newer than "2022.xx.yy.zz" or whatever the original bundle versions were before
+    # we switched to uniform naming.
+    - pwsh: |-
+        $VersionEpoch = 3000
+        $Components = "$(XES_APPXMANIFESTVERSION)" -Split "\."
+        $Components[0] = ([int]$Components[0] + $VersionEpoch)
+        $BundleVersion = $Components -Join "."
+        .\build\scripts\Create-AppxBundle.ps1 -InputPath "$(System.ArtifactsDirectory)" -ProjectName CascadiaPackage -BundleVersion $BundleVersion -OutputPath "$(System.ArtifactsDirectory)\Microsoft.WindowsTerminal_$(TerminalTargetWindowsVersion)_$(XES_APPXMANIFESTVERSION)_8wekyb3d8bbwe.msixbundle"
       displayName: Create WindowsTerminal*.msixbundle
-      inputs:
-        filePath: build\scripts\Create-AppxBundle.ps1
-        arguments: -InputPath "$(System.ArtifactsDirectory)" -ProjectName CascadiaPackage -BundleVersion $(XES_APPXMANIFESTVERSION) -OutputPath "$(System.ArtifactsDirectory)\Microsoft.WindowsTerminal_$(TerminalTargetWindowsVersion)_$(XES_APPXMANIFESTVERSION)_8wekyb3d8bbwe.msixbundle"
     - task: EsrpCodeSigning@1
       displayName: Submit *.msixbundle to ESRP for code signing
       inputs:


Test patch: