Understanding the MSIX Manager Sample
This sample demonstrates how to programmatically interact with MSIX packages on Windows using the MSIX Packaging API. It provides a foundation for building custom tools to manage application installations, updates, and uninstalls, offering greater control and automation capabilities for developers and IT professionals.
Key Features Showcased
- Listing installed MSIX packages.
- Installing new MSIX packages.
- Updating existing MSIX packages.
- Uninstalling MSIX packages.
- Retrieving detailed information about a package (version, publisher, etc.).
- Handling package dependencies and optional packages.
Setup and Prerequisites
To run this sample, ensure you have the following:
- Windows 10/11: With appropriate build version for MSIX support.
- Visual Studio: Version 2019 or later, with the ".NET desktop development" workload installed.
- MSIX Packaging Tool: (Optional, but recommended for creating test packages).
- Developer Mode: Enabled on your Windows machine.
Clone the repository from the official Microsoft GitHub or download the source code directly.
Usage Guide
The sample application provides a simple command-line interface (CLI) or a basic GUI (depending on the implementation) to perform the following operations:
- List Packages: Executes a command to display all MSIX packages installed on the system.
- Install Package: Prompts for the path to an MSIX file and initiates the installation.
- Update Package: Prompts for the path to an MSIX update file and applies it to the existing installation.
- Uninstall Package: Prompts for the package name or family name and removes it.
Core Code Snippet (Conceptual C#)
Here’s a glimpse into the core logic for uninstalling a package. The full sample provides more comprehensive examples for all operations.
using Microsoft.WindowsAppRuntime.Packaging;
using System;
using System.Linq;
public class MsixPackageManager
{
public void UninstallPackage(string packageFamilyName)
{
try
{
var package = MsixPackageManager.Current.FindPackagesForCurrentUser().FirstOrDefault(p => p.PackageFamilyName == packageFamilyName);
if (package != null)
{
Console.WriteLine($"Uninstalling package: {package.PackageFullName}...");
MsixPackageManager.Current.RemovePackage(package.PackageFullName);
Console.WriteLine("Package uninstalled successfully.");
}
else
{
Console.WriteLine($"Package '{packageFamilyName}' not found for the current user.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error uninstalling package: {ex.Message}");
}
}
// Add methods for InstallPackage, UpdatePackage, FindPackages, etc.
}
Advanced Topics
Explore further by integrating MSIX management into your CI/CD pipelines, handling different deployment targets (e.g., enterprise deployments), or managing application updates through a custom catalog.
Troubleshooting Common Issues
- Permissions: Ensure your application has the necessary administrative rights.
- Package Dependencies: Verify that all required framework packages are installed.
- Corrupted Packages: Sometimes, a repair operation or clean uninstall/reinstall is needed.
- API Version Mismatch: Ensure you are using the correct version of the MSIX Packaging API for your Windows version.