2

I packaged a Win32 console app into an MSIX package. Everything works fine on Win 10. I can also install it on Windows Server 2019, but have no way of running it there from the console by calling the alias or any other means.

  1. The app is installed in C:\Program Files\WindowsApps\stackmuncher_1.1.1.0_x64__eqf80b1s88fx6
  2. There is an alias for it in C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps as a zero-length file
  3. I can run the app if I copy the executable from C:\Program Files\WindowsApps\stackmuncher_1.1.1.0_x64__eqf80b1s88fx6 to any other folder
  4. The alias is showing in Settings > App Execution Aliases

If I try to run the app by its alias stackmuncher.exe from PS or CMD terminal I get a "not found" message.

I added %userprofile%\AppData\Local\Microsoft\WindowsApps to system Path variable and got a different error:

Program 'stackmuncher.exe' failed to run: The specified executable is not a valid application for this OS platform

It seems that the app was installed and all the files it needs to function properly are there.

How can I run it using an alias or in any other way?


Package info

PS C:\rust\stm> get-appxpackage |  Where-Object { $_.Name -like "*stackmuncher*" }

Name              : stackmuncher
Publisher         : CN=stackmuncher, C=NZ
Architecture      : X64
ResourceId        :
Version           : 1.1.1.0
PackageFullName   : stackmuncher_1.1.1.0_x64__eqf80b1s88fx6
InstallLocation   : C:\Program Files\WindowsApps\stackmuncher_1.1.1.0_x64__eqf80b1s88fx6
IsFramework       : False
PackageFamilyName : stackmuncher_eqf80b1s88fx6
PublisherId       : eqf80b1s88fx6
IsResourcePackage : False
IsBundle          : False
IsDevelopmentMode : False
NonRemovable      : False
IsPartiallyStaged : False
SignatureKind     : Developer
Status            : Ok

AppManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<Package
    xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
  xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 
  >
  <Identity Name="stackmuncher" Version="1.1.1.0" Publisher="CN=stackmuncher, C=NZ" ProcessorArchitecture="x64" />
    <Properties>
       <DisplayName>stackmuncher</DisplayName>
       <PublisherDisplayName>stackmuncher</PublisherDisplayName>
             <Description>stackmuncher app</Description>
      <Logo>150.png</Logo>
    </Properties>
    <Resources>
      <Resource Language="en-us" />
    </Resources>
      <Dependencies>
        <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14316.0" MaxVersionTested="10.0.15063.0" />
      </Dependencies>
      <Capabilities>
        <rescap:Capability Name="runFullTrust"/>
      </Capabilities>
    <Applications>
      <Application Id="stackmuncher" Executable="stackmuncher.exe" EntryPoint="Windows.PartialTrustApplication">
        <uap:VisualElements DisplayName="stackmuncher" Description="stackmuncher app"   Square150x150Logo="150.png" Square44x44Logo="44.png"    BackgroundColor="#999999" />
        <Extensions>
          <uap3:Extension Category="windows.appExecutionAlias" EntryPoint="Windows.FullTrustApplication" Executable="stackmuncher.exe">
            <uap3:AppExecutionAlias>
              <desktop:ExecutionAlias Alias="stackmuncher.exe"/>
            </uap3:AppExecutionAlias>
          </uap3:Extension>
        </Extensions>
      </Application>
    </Applications>
  </Package>

Full error message

PS C:\> stackmuncher.exe
Program 'stackmuncher.exe' failed to run: The specified executable is not a valid application for this OS platform.At
line:1 char:1
+ stackmuncher.exe
+ ~~~~~~~~~~~~~~~~.
At line:1 char:1
+ stackmuncher.exe
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed
max
  • 510
  • 3
  • 13
  • MSIX docs clearly state that execution aliases are not supported on WinServer 2019 (https://learn.microsoft.com/en-us/windows/msix/msix-server-2019). It seems they are supported up to a point - the alias is created, but cannot be invoked the same way as on Win10 or maybe there is just no way to invoke it. – max May 12 '21 at 00:05

1 Answers1

0

As you mentioned in your comment, Win Server 2019 doesn't support execution aliases (sadly). I've just faced the same issue trying to test my MSIX package on GitHub Actions, which uses Windows Server 2019.

I found several ways to run the installed package.

  1. Using PowerShell command Invoke-CommandInDesktopPackage. You can invoke your main executable as well. I tested this approach, it works (on my machine though), but it's difficult to do this from code and then attach it to the target application process.

  2. Another way is to run the app using a command like explorer.exe shell:appsFolder\<ApplicationID>!<AppID>. This approach described here with handy scripts. I haven't found a way to add command-line args, so it was not OK for me.

  3. Using protocol. It requires additional changes to the app, but for me, it was the easiest and the most reliable way. So I added protocol support for my app as described in this article. In my code I just added a few lines to support that type of argument:

     public AppConfigBuilder AppendCommandLineArgs(string[] args)
     {
         const string protocol = "myproto:?";
    
         bool isProtocolUsage = args.Any() && args[0].StartsWith(protocol);
    
         string[] keyValueArgs = isProtocolUsage
             ? args[0][(args[0].IndexOf("?", StringComparison.Ordinal) + 1)..].Split('&')
             : args;
    
         var configuration = new ConfigurationBuilder()
             .AddCommandLine(keyValueArgs)
             .Build();
    
             ...
     }
    

Basically, I converted it to regular args and passes it to the ConfigurationBuilder, which handled it well.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Lev
  • 811
  • 12
  • 13