torum

主に開発中のアプリにまつわる技術系の事。

Package a Lazarus desktop application using the Desktop App Converter

I recently converted my Lazarus win32 application into an appx package and submitted it to Microsoft Store.

If you haven’t submitted an application before, it is very easy to get lost. So I thought I should document a procedure to package an existing Lazarus application manually using Desktop App Converter.

Anybody can copy, modify and use the contents of this page. It is more than welcome to add this to Lazarus wiki page.

Prerequisite

First, you have to make sure your app runs on Windows 10 S as well which is a requirement for store apps.

Here, we suppose we have a simple single executable with/without some translation files. (You don’t need to create an installer)

For simplicity, compile your apps in 32 bit using Lazarus add-on if you are on 64 bit OS  (You could, I believe, include 32bit and 64bit exe separably in an Appxbundle if you are willing to go though all the hassle…).

Preparation

  1. Register as an app developer at Microsoft website.

    https://developer.microsoft.com/en-us/store/register

  2. Submit a form about your apps.
  3. Log in to Microsoft Dev Center and reserve an app name.

    https://developer.microsoft.com/dashboard

You have to submit a form (step 2) and receive (It takes 6 business days or more) a replay. Then, you must submit appx package and get approval for “runFullTrust” privilege from Microsoft before actually submitting your app to Microsoft Store at Microsoft Dev center.

Store apps (or UWP apps) are supposed to declare their capabilities such as accessing cameras, contacts or photos etc. But since Win32 apps don’t have those limitations, Win32 apps run as full privileged aka “runFullTrust”. So, Win32 apps requires this extra step.


Using Desktop App Converter

  1. Download and install “Desktop App Converter” from Microsoft Store.
  2. Start “Desktop App Converter” as Administrator.
  3. Execute DesktopAppConverter in the Windows PowerShell
  4. Edit AppxManifest.xml manually.
  5. Create resource files (logo images) in the \PackageFiles\Assets
  6. Add-AppxPackage -Register AppxManifest.xml to test it locally.
  7. Execute MakeAppx to create an appx package.
  8. Check appx with “Windows App Certification Kit”
  9. Upload it to Microsoft Dev Center.


Download and install “Desktop App Converter” from Microsoft Store.
Here is the link. You may be asked to install Windows SDK if it is not installed on your system already.

Start “Desktop App Converter” as Administrator.

From the “start” menu, launch  “Desktop App Converter” as an Administrator.

The Windows PowerShell should appear.

Execute DesktopAppConverter in the Windows PowerShell

Suppose we have a directory structure below.

C:\
├ Apps
│ ├ hoge
│ │ ├ hoge.exe
│ │ ├ locale
│ │ │ ├ hoge.en.po
│ │ │ └ hoge.ja.po
└ Output

The command would be

 

DesktopAppConverter.exe -Installer C:\Apps\hoge\ -AppExecutable hoge.exe -Destination C:\Output

 

You’ll be asked:

PackageName
PackageName should match with your package ID/Name shown in the dashboard in Microsoft Dev Center. (something like 5 digit<your display name>.<apps name>)

Publisher
publisher should match with your package publisher shown in the dashboard in Microsoft Dev Center. (something like CN=*******-****-****-****-************)

Version
0.1.0.0 something like this. Version must be 1 or above . The last digit must be 0.

 

Alternatively, you could specify them as command-line option.

DesktopAppConverter.exe -Installer C:\Apps\hoge\ -AppExecutable hoge.exe -Destination C:\Output -PackageName "<PackageName>" -Publisher "<Publisher>" -Version <Version> -MakeAppx -Verbose -Verify

 

You’ll get something like,

C:\
└ Output
  └ <PackageName>
    └ PackageFiles
      ├ Assets
      │ ├ *.png
      │ └ …
      ├ locale
      │ ├ hoge.en.po
      │ └ hoge.ja.po
      ├ AppxManifest.xml
      ├ hoge.exe
      └ resources.pri

 

*If you specify “-MakeAppx” you’ll find “<PackageName>.appx” in the output directory.

However, you are not done yet. If you want to customize the installation such as file type associations, you have to edit AppxManifest.xml manually and use MakeAppx.

 

Edit AppxManifest.xml manually.


My AppxManifest.xml looks something like below.

 

<?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:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:rescap3="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities/3" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" xmlns:desktop2="http://schemas.microsoft.com/appx/manifest/desktop/windows10/2" xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10" xmlns:wincap3="http://schemas.microsoft.com/appx/manifest/foundation/windows10/windowscapabilities/3" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" IgnorableNamespaces="uap4 uap5 wincap3 rescap3 desktop2 com">
<Identity Name="<PackageName>" ProcessorArchitecture="x86" Publisher="<Publisher>" Version="<Version>" />
<Properties>
<DisplayName>hoge!</DisplayName>
<PublisherDisplayName>fuga<Publisher></PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Resources>
<Resource Language="en-us" />
<Resource uap:Scale="100" />
<Resource uap:Scale="125" />
<Resource uap:Scale="150" />
<Resource uap:Scale="200" />
<Resource uap:Scale="400" />
</Resources>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.16299.15" />
</Dependencies>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
<Applications>
<Application Id="hoge" Executable="hoge.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="hoge!" Description="created with lazarus" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" Square310x310Logo="Assets\Square310x310Logo.png" Square71x71Logo="Assets\Square71x71Logo.png">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo" />
<uap:ShowOn Tile="wide310x150Logo" />
<uap:ShowOn Tile="square310x310Logo" />
</uap:ShowNameOnTiles>
</uap:DefaultTile>
</uap:VisualElements>
</Application>
</Applications>
</Package>

 

First, you might want to change following values.

//Package/Properties/DisplayName

//Package/Applications/Application/uap:VisualElements/@DisplayName

//Package/Applications/Application/uap:VisualElements/@Description

These are shown in the .. well lot of places including in the start menu.

Also, you might wanna add

//Package/Applications/Application/uap:VisualElements/uap:DefaultTile/@ShortName

This will be displayed in the tile menu.

 

If your app needs file type associations, etc, here is the place to add these. For more information about see App package manifest. And Package manifest schema reference for Windows 10.

 

Create resource files (logo images) in the \PackageFiles\Assets

DesktopAppConverter will auto generate “Assets” – logos and icons from icon resource in your apps, but you want to change/replace them because they look “ugly” in many cases.

 

C:\
└ Output
  └ <PackageName>
    ├ PackageFiles
    │ ├ Assets
    │ │ ├ *.png
    │ │ └ …

 Be aware. There are more than 40 files!!!

 

Check appx locally

In the command-line, run

 

Add-AppxPackage -Register C:\Output\<PackageName>\PackageFiles\AppxManifest.xml

 You should now see your app in the start menu.

Execute MakeAppx to create an appx package.

 

MakeApps.exe is located somewhere deep in the sys directory with probably with Windows SDK, so you might need to register environment “PATH”.

Search “makeappx.exe” in your c dorive and add the path to PATH.

For more info on MakeApp or here.

And run,

 

makeappx.exe pack /d C:\Outputs\<PackageName>\PackageFiles /p C:\Outputs\<PackageName>.appx

 

Done!

You should now find <PackageName>.appx file in your output directory.

 

Check appx with “Windows App Cert Kit”


This is the final step before submitting to the store. This step is important because if this fails, your submission to the store will be automatically rejected.

 

Search “Windows App Cert Kit” in the start menu and launch it. Select “Store app” not the “desktop app”. If you get errors, fix them.

 

Upload it to Microsoft Dev Center.


Make sure you received an approval for “runFullTrust” privilege by Microsoft before hit submit button.