TX Text Control .NET for WPF

MSIX Packaging and Microsoft Store Deployment

Topic

Packaged as MSIX, a WPF application with TX Text Control can be sideloaded onto machines in your organization or submitted to the Microsoft Store. Visual Studio builds the package from a Windows Application Packaging Project that references your WPF project, and the project's reference to the NuGet package TXTextControl.TextControl.WPF.SDK comes along with it. What follows sets up the packaging project, creates and signs a package, installs it for a test and shows how to run the application in an AppContainer.

Prerequisites

  • A WPF application for .NET 8 or higher with TXTextControl.TextControl.WPF.SDK; see Create Your First WPF Application.

  • The Visual Studio component MSIX Packaging Tools: open the Visual Studio Installer, choose Modify, and check MSIX Packaging Tools among the optional components of the workload .NET desktop development.

    The Visual Studio Installer modifying Visual Studio 2022, with the workload .NET desktop development selected and the optional component MSIX Packaging Tools checked in the installation details.

Create the Packaging Project

  1. In Solution Explorer, right-click the solution, and choose Add > New Project.

  2. Find the template Windows Application Packaging Project, and click Next.

  3. Name the project, and click Create.

  4. Choose the target version and the minimum version of Windows for the package, and click OK. Text Control's walkthrough uses Windows 10, version 1809 as the minimum:

    The New Windows Project dialog, which asks for the target version, here Windows 10, version 2004, and the minimum version, here Windows 10, version 1809.

  5. Right-click the packaging project, choose Add > Project Reference, check the WPF project, and click OK.

  6. Right-click the packaging project again, and choose Set as Startup Project.

The WPF project now appears under Dependencies > Applications of the packaging project, together with its package reference.

Build and Sign the Package

  1. With the packaging project selected, choose Project > Publish > Create App Packages.

  2. Select the distribution method. Sideloading creates a package you install yourself; the Microsoft Store is the alternative for public distribution. For a first test, choose Sideloading, clear Enable automatic updates, and click Next:

    The page Select distribution method of the Create App Packages dialog, with Sideloading selected and Enable automatic updates not checked.

  3. On the signing page, select Yes, select a certificate, and pick the certificate for the package. Create makes a self-signed certificate if you have none. Continue with Next.

  4. Check the architectures to build, for example x64, and click Create:

    The page Select and configure packages of the Create App Packages dialog, where the x64 architecture is checked with the solution configuration Debug (x64).

The architecture corresponds to a platform of your solution. x86, x64, and AnyCPU explains what the platform means for the native libraries of TX Text Control.

Sideload the Package for a Test

Windows installs a sideloaded package only if it trusts the certificate the package was signed with.

  1. Open the output folder of the package, right-click the .cer file, and choose Install Certificate.

  2. Choose Local Machine, and click Next.

  3. Choose Place all certificates in the following store, browse to Trusted Root Certification Authorities, and finish the wizard with Next and Finish.

    The Certificate Store page of the Certificate Import Wizard with Place all certificates in the following store selected and the store Trusted Root Certification Authorities.

  4. Double-click the .msixbundle file, and click Install.

Windows installs the application and starts it.

Run in an AppContainer

With .NET, Windows Forms and WPF applications can run in an AppContainer: an isolation in which the application reaches resources such as the camera, the microphone, the location or user data only if its package declares them.

  1. In Solution Explorer, expand Dependencies > Applications of the packaging project, and select the WPF application.

  2. In the Properties window, change Trust Level to Partial Trust. The setting is the same for a Windows Forms and a WPF application; the picture shows the project reference of a Windows Forms project:

    The Properties window of a project reference with the Trust Level set to Partial Trust.

  3. In the packaging project, open Package.appxmanifest, switch to Capabilities, and check what the application has to reach:

    The Capabilities page of Package.appxmanifest with a list of capabilities, of which Internet (Client) and Microphone are checked.

The packaged application then has access to the declared resources and no others. Text Control's article Secure and Deploy .NET Windows Forms Apps with MSIX AppContainer Apps demonstrates it with a Windows Forms application; the settings are those of the packaging project.

Learn More

The blog article Deploying Windows Forms and WPF to Windows Store using MSIX walks through packaging and sideloading with screenshots, written for version 31.0 and .NET 6.

Next Steps