We've just announced the public preview of the Desktop App Converter, which enables you to take a traditional Win32 app and convert it into the Windows 10 app packaging format (APPX). Formerly known as Project Centennial, this toolkit is designed to bring many of the benefits of UWP and the modern store to all Windows apps: including app isolation, easy discovery and installation, commerce, and access to WinRT APIs.
I thought I'd have a go at trying this out with one of my favorite utilities: Notepad2, which is a powerful freeware text editor that substitutes nicely for the system Notepad. The primary maintainer of this app somewhat abandoned it, but others have taken up the mantle and so there are some good forks, most notably Notepad2-mod. Since this has a permissive BSD license, I thought I'd take a shot at running it through the Desktop App Converter to see how it worked.
Behind the scenes, the tool uses the new support for Containers in Windows 10 Anniversary Update. It spins up a base container image for Windows 10, installs the Win32 app inside the virtualized environment, and tracks what the conventional installer does to the file system and registry. It then builds an APPX out of that information which can be used to install it on any machine. Once installed, the app runs in a partitioned environment on a target machine. As far as the app is concerned, it's running natively on the machine, but really Windows is intercepting and detouring calls into a isolated space.
The process proved pretty straightforward, and I thought I'd share it with others.
First I grabbed the Desktop App Converter tool, which is pleasingly available from the Windows store itself at http://aka.ms/converter. I then downloaded the base container image for the Windows build I'm using.
One great thing about the app converter tool is that technically you don't even need the source code to create the APPX package. As mentioned above, it captures the output of the installer itself. But nevertheless, I'm using this opportunity to build Notepad2-mod on my own machine.
I've already installed Visual Studio 2015 (including the Windows SDK) and Inno Setup, both of which are required to build this project:
[C:\git] git clone --recursive https://github.com/XhmikosR/notepad2-mod [C:\git\notepad2-mod] update_rev.bat [C:\git\notepad2-mod\build] make_all_vs2015.bat
Time to launch PowerShell as an admin and install the downloaded base container image into the container so DesktopAppConverter can use it:
PS C:\baseimages> DesktopAppConverter -setup -baseimage C:\baseimages\BaseImage-14393.wim
I hadn't already installed the containers feature on this machine, so I was prompted to restart Windows before continuing. You then have to rerun the command to complete the installation.
PS C:\git\notepad2-mod\appx> DesktopAppConverter -setup -baseimage C:\baseimages\BaseImage-14393.wim LogPath : C:\WINDOWS\Logs\DISM\dism.log C:\ProgramData\Microsoft\Windows\Images\BaseImage-14393 6ff86713-0b1d-413b-b3b9-a3ffe0b7b208
OK good. So I now have a working base image container for Centennial to use.
Now it's time to run the tool a second time in order to capture the recipe and build the APPX. It's a fairly unwieldy set of command-line options, but fortunately the tool documentation is already pretty good.
PS C:\git\notepad2-mod\appx> DesktopAppConverter.exe -Installer "C:\git\notepad2-mod\build\packages\Notepad2-mod.22.214.171.1246.exe" -InstallerArguments "/verysilent /dir=c:\notepad2" -AppInstallPath "c:\Notepad2" -Destination "c:\git\notepad2-mod\appx\output" -PackageName Notepad2 -Publisher "CN=Tim Sneath" -AppDescription "Fast and lightweight Notepad-like text editor with syntax highlighting" -Version 126.96.36.199 -MakeAppx -Sign
A few comments about certain command-line arguments:
- It's important that your installer is capable of silent / quiet installation (i.e. that it doesn't display blocking UI), since you won't be able to interact with it while the converter tool is capturing what gets installed. Hence the
/verysilentparameter passed to the Notepad2 installer;
- By default, the converter wasn't able to find the resultant files from Notepad2. So I added both a
/dirparameter to the Inno Setup installer, and
-AppInstallPathto the DesktopAppConverter parameters to put it into a known location;
Destinationparameter is for where the finished APPX should be placed, not where the app is installed to.
- Note that the least-significant value of the version (revision number) must be 0, for reasons that are opaque to me. So instead of the ideal
188.8.131.526, we’re therefore going with
184.108.40.206as the version number.
If all goes well, you'll find an APPX file in the resultant directory:
PS C:\git\notepad2-mod\appx> dir .\output\Notepad2\*.appx Directory: C:\git\notepad2-mod\appx\output\Notepad2 Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 9/14/2016 3:58 PM 4754288 Notepad2.appx
Yay! But you can't successfully run it yet because the certificate used to sign the APPX isn't yet trusted by Windows.
If you had a trusted certificate, you could have altered the command slightly to use that instead, but since we passed the
-Sign parameter, the
DesktopAppConverter tool itself generated a certificate that you must install to the cert store, with a command like the following:
PS C:\git\notepad2-mod\appx> Certutil -addStore TrustedPeople .\output\Notepad2\auto-generated.cer TrustedPeople "Trusted People" Signature matches Public Key Certificate "Tim Sneath" added to store. CertUtil: -addstore command completed successfully.
Great! Now we can go ahead and try out our shiny new APPX file, by simply double-clicking it or running it from the command line:
And the Install button works!
Checking out the properties of the running application from Task Manager demonstrates that this is installed not to the usual
C:\Program Files directory, but to the same root folder as UWP apps:
Flushed by my success, I thought I’d be a little cheeky and try uploading to the Windows store. That proves a little more difficult at the moment. I was able to sign into the store dashboard, reserve the app name and set all the project attributes. (As an aside, the Windows Store submission process has really improved over the months: it's a much more user-friendly process than it used to be.)
And I got so close. Unfortunately my account isn’t yet enabled to upload Centennial applications to the Windows store, so I get the following message:
The first error looks like a bug in Desktop App Converter – it copies the fully publisher name of
CN=Tim Sneath into the display name, which then fails to match against my actual store publisher name. I fixed that by adding the
-PackagePublisherDisplayName optional parameter to the DesktopAppConverter command, as follows:
PS C:\git\notepad2-mod\appx> DesktopAppConverter.exe -Installer "C:\git\notepad2-mod\build\packages\Notepad2-mod.220.127.116.116.exe" -InstallerArguments "/verysilent /dir=c:\notepad2" -AppInstallPath "c:\Notepad2" -Destination "c:\git\notepad2-mod\appx\output" -PackageName Notepad2 -Publisher "CN=Tim Sneath" -PackagePublisherDisplayName "Tim Sneath" -AppDescription "Fast and lightweight Notepad-like text editor with syntax highlighting" -Version 18.104.22.168 -MakeAppx -Sign
(Note that this will generate a fresh certificate, so you'll have to run
CertUtil again to install this locally.)
But even after fixing this, I'm still blocked (for now) from uploading this app to the store because my developer account is not yet approved for publishing:
So close! And at least I have something that I can work with for now. Perhaps time to add a few other features to Notepad2 in the meantime: high-DPI support, perhaps?