In a previous post, I’ve shown how to package a Delphi application for the Windows Store, and in this post I’ve shown how to package a WPF application. In both cases, the apps were packaged alone or with their references, so there was no trouble to package them to the store.

In the last post, I’ve refactored the Financial Calculator into a main app and a dll, so the code for the calculators could be reusable and testable. Now we have to package the apps for the store again, but this time there will be an extra task: to package the dll together with the app. In this article, I’ll show how to do that for both applications, the Delphi and the WPF one.

Packaging a Delphi app

To package the Delphi app, we just need to go to the project, select the Application Store configuration, then go to Project/Options/Provisioning and select the Ad Hoc deployment and add the certificate we created earlier. Then, we run the packaging and install the appx file. When you install and run the app, you will see a message like this:

That’s because the dll wasn’t packaged with the executable. If you rename the appx file to zip and open it with a zip manager (yes, an appx file is a zip file with another extension), you will see something like this:

As you can see, the appx file is a zip file with all the content needed to run the app. If you take a look at it, you will see that the dll isn’t there, that’s why you get the message. There is nothing that says that the dll should be added to the package, there are no references and the load of the dll is only done at runtime, so the packager doesn’t knows the dll is needed. We must do some things, so the dll is packaged with the app.

Go to the Projects window and right click on the FinCalc.exe node and select the Add option. Then add the FinCalcDll.dll to the project:

Now, when you rebuild the app, you will see that FinCalcDll.dll was added to the appx file and it will be used when you install it from the store:

There is something to note, here: this setting won’t work for the normal app. If you want to run the app as a normal app, you must continue to xcopy the dll to the output directory, this setting won’t copy it to the output directory. So, to be safe, do both things:

  • Add the dll to the project
  • Xcopy the dll to the output dir

Packaging a WPF app

Now that we’ve packaged the Delphi app with the dll, we must package the WPF app. To create a package to a WPF app, we must create a packaging project in Visual Studio:

Once the new project is created, in the Solution Explorer, you must right-click in the Applications node and select Add Reference. Then you must add the WPF project to the package. Then, right click on the project node and select Store/Create App Packages. There you can select if you want to create packages for the Store or for Sideloading:

If you want to create an app for the store, you must have a developer account and associate a name for the app in the store. We will choose to sideload the app:

Here we must note some things: as our dll is a 32 bit one, we must choose the x86 package only. We don’t need and app bundle, where all the platforms are packaged in a single file – we will use the “Generate app bundle” to Never, then click Create. That will create the appx package and show the folder where it was created. Opening the folder, you will find some files to install the app, including the appx file.

If you double click on it and click on Install, you will see something like this (just for the first time):

That’s because the certificate you’ve used is not installed in the machine. To install it, you can open the Package.appxmanifest file in Visual Studio and go to the Packaging tab:

Then, click on the Choose Certificate button and then on View Full Certificate. That will open the install certificate window:

You must click on the Install Certificate button and select Local Machine as the store location. Then click on Next and then in Place all certificates in the following store, clicking on Browse and selecting Trusted People. The certificate will be installed and you can click again in the Appx file to install it.

This app will run without problems, because the dll will be added to the package. Adding the dll in the original project as content will make it to be packaged for the store, there’s nothing else to do.

Conclusions

As you can see, packaging an app with a dll for the Windows Store is not too difficult, but you must be aware of these things, so the app doesn’t fail when running, for the lack of the dll.

All the source code for these projects are at https://github.com/bsonnino/FinCalcDll

 

On last post, I’ve shown how to publish a .NET app to the store. This is quite easy with Visual Studio, but the app must be a .NET app and it must be ported to .NET 4.6.1 or later. Many times, this is not possible – you have a .NET app that targets an older version of the framework and cannot be updated or you have a Win32 app (have I heard VB6 or Delphi?) that you want to publish to the store. Sometimes, even the source code is lost and all you have is the installer or executable. Even with this case there is no problem: you can still publish it to the store, the only thing is that you won’t be able to use Visual Studio.

To demonstrate it, I will use an old Delphi game sample, Swat!, which source code is in the Delphi samples since the earlier versions of Delphi (I think it’s there since Delphi 1, in 1994).

In this game, you must kill the ants with a hammer, this is an old game and I used it as an example of what you can convert to the Store.

The first step is to download the Desktop app converter from the store

Once you have it installed, you should run it with admin rights: in the start menu, right click in its icon and select “More/Run as administrator”. That will open a console window where you will run the converter app.

This window shows some examples of command line for packaging your app, but the first example must always be run once to setup the environment. You must download a base image for your system and run the setup. The base image can be downloaded from here, it must be compatible with your system version. You can check the system version by pressing Win+R and running winver:

My Windows version is 16299. so I have to donwload the base image for that version. It will be downloaded in my downloads folder, with the name “Windows_InsiderPreview_DAC_16299.wim”. So, the first step is to run the command line:

DesktopAppConverter.exe -Setup -BaseImage "E:\Downloads\Windows_InsiderPreview_DAC_16299.wim"

You may have an error after running this command line. This is because the Containers feature must be enabled in your system. Note: you must have Windows 10 Pro or Enterprise to enable this feature – if you have Windows 10 Home, you won’t be able to use the packager:

The converter will add this feature, but you must restart your machine. When you restart it, the Desktop App Converter will reopen and re-run the setup. You are then ready to package your app. The program we are running doesn’t have an installer, it is a single file. If you have an installer, you can point DesktopAppConverter to it, but in this case, we just need to create a folder and put all the files we need there (in this case, just the executable) and another folder for the output. Note: don’t create an output folder as a subfolder from the install folder – I did that and got an error “Path too long” – this is because the output folder is added as an install folder and this is recursive – newbie mistake. Then we must run this command line:

DesktopAppConverter.exe -Installer D:\Temp\Swat\ -AppExecutable Swat.exe -Destination D:\Temp\SwatUWP -PackageName "SwatUWP" -Publisher "CN=RevolutionSoft" -Version 0.0.0.1 -MakeAppx -Sign -Verbose -Verify

This will add all the files in D:\Temp\Swat and create the output file in D:\Temp\SwatUWP, creating and signing an appx file. You can go to the output folder and double click the Appx file. It will open the installer for the app:

If it’s the first time you are installing the app, you will get an error, because the certificate is not installed. You can install it by going to the output folder and double clicking the cer file. That will open the install certificate window:

You must click on the Install Certificate button and select Local Machine as the store location. Then click on Next and then in Place all certificates in the following store, clicking on Browse and selecting Trusted People. The certificate will be installed and you can click again in the Appx file to install it. Now you have your app running as a UWP app.

If you have an installer (it can be an MSI or an EXE installer) that can be run unattended, you can use it to convert your app. In this case, all the files in the installer will be added to the package.

Now it’s time to customize the package, but this is something for another post.

 

 

You have an old app (maybe a WPF or even a VB6 app), it still works fine, but the plans to rewrite it to UWP and get all the features for Windows 10 are always postponed (yes, there is always something more urgent than rewrite an app that is working fine). But, at the same time, you would like to publish it to the Store to get the benefits of being there: easy install and uninstall, worldwide discovery (you always knew there was somebody in the other side of the world that would benefit of the app), easy deploy, checking against viruses and other threats, and even monetization of the app – it would be nice to sell the app and receive the revenues at the end of the month without worrying with that.

Until some time ago, that would be impossible to do, unless you did a complete rewrite of the app, but with the Desktop Bridge, this is possible. And you can do it in many ways: you can just convert your app without any changes (you don’t even need the source code for the app), you can add some Windows 10 features to it, rewrite some parts of the app to UWP and so on. That way, you can start immediately and convert the app at your own pace. That will give you all the benefits of the store at once and you don’t need to worry with the conversion until you are ready for it.

Can your app be converted?

Before converting your app, you must be sure it can be converted and, if not, you must make some changes to make it compliant with the conversion. These are good practices that should be done even before thinking to convert:

  • Running in elevated mode – converted apps cannot run in elevated mode. Do you really need elevated mode? If not, you must change your app before converting.
  • Write in the install folder – this is one of the most common mistakes done by old apps. This is not allowed in UWP apps and, unless you change this to write in another folder, your app won’t be approved.
  • Write in system folders – yes, Microsoft has something to do with this issue. When you were using ini files to save your configuration, the default folder for them was in the Windows folder
  • Write in the HKLM registry hive. If you have this in your app, you must change it to HKCU instead

There are some other issues that may prevent your app to be submitted to the Store. You can check them here.

Starting the conversion process

Once you are sure that your app can be converted, you can start the conversion. The first step for the conversion is filling a form here. This is needed because the submission process will be different from normal UWP apps. The converted apps will have full thrust in the machine they are installed and they must be double-checked. One other issue is that you don’t need the source code, so you must be the legal owner of the app to publish it (and you must have some kind of proof of that). Once you have that in place, you can convert your app. You have three ways to convert it:

  • using Visual Studio (you must have the source code for that and the project must be opened in Visual Studio (in this case, you cannot convert your VB6 projects or any project that cannot be opened in Visual Studio)
  • using the Desktop App Converter – this is a Store app that must be run to convert your app. In this case, you have more flexibility than using Visual Studio: you can convert any app, including Win32 ones. You just need to have an installer that runs silently (with no user interaction)
  • Doing a manual conversion – this is the most flexible way, you can choose the files that will be packaged and how they will be, but this way will require more work and knowledge.

Using Visual Studio to convert a WPF app

We will use Visual Studio to convert my Data Structures app, discussed in the posts from 2016 (the last one in the series is here). You can get the full project in https://github.com/bsonnino/DataStructures. Once you download it and open it in Visual Studio, you are ready to convert it to the Store.

The first step here is to convert it to use the .NET Framework version 4.6.1 or later. You need that to convert the app to the store, as this is the minimum version supported there. You can do that by going to Project/Options/Application:

The next step is to add a new project to the solution, of type Windows Application Packaging Project (under Windows Universal):

Name it DataStructuresUWP. That will be the name of your UWP app. You must select the Windows version 14393 as the minimum version:

When the project is created, you must right click the Applications node and add the application as a reference

Once the app is added, you can right-click in the node under Applications and select “Set as Entry Point”. You are now ready to create the UWP app, by selecting the conversion project in the Solution Explorer, right-clicking on it and selecting “Store/Create app packages”.

When you select to build the package for the App Store, you need to have an account there (you can create an account at http://dev.windows.com) and select a name for your app:

You can also create packages that won’t go to the store and will be installed in the local machine. When you create the package, a link where the files will be located is shown and you must right click the Add-AppDevPackage.ps1 file and select “Run With Powershell”.

By distributing these files, you can sideload the app in any machine that has the developer mode enabled (in the Windows Settings). In our case, we have a faster way to install and run the app: just right click the conversion project in the Solution Explorer and select “Set as Startup Project”. Now, when you run the project, you will install and run the converted app, which is an UWP app. If you see the icon for the app in the taskbar, you will see the default UWP icon (the square with an X) and opening the start menu, you will see the installed app there.

That was easy, no? Now, you can customize your app to make it better for the store.

Customizing the app for the store

Now that the app is converted, you can customize it for the store by setting its name and assets (icons, tiles, etc). This is done by double clicking the Package.appxmanifest file in the Solution Explorer:

There, you can change its display name, icons and tiles and make it ready for sending to the store. With this, your app is ready for the store and you already have all the benefits of being there. As you can see, the changes were minimal and your app still runs the same. If you still want to use your WPF app, the only change that was made is to retarget for the 4.6.1 .NET Framework. In this case, we had the source code to build the app, but in the next article I will show how to convert a Win32 app with no source code, so you can get the same benefits. See you there!