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.
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