如何让可选包中的应用使用主包的虚拟化文件系统与注册表运行?
Great question—this is a common point of confusion with MSIX related sets, especially when you want a unified file system and registry view across your main and optional packages. Let’s break down what’s happening and how to fix it:
Why You’re Seeing Separate VFS Environments
By default, even within a related set, each MSIX package (main and optional) gets its own isolated virtual file system (VFS) and registry hive. The Invoke-CommandInDesktopPackage test you ran lets you access the physical WindowsApps folder (via OS-level permissions), but that doesn’t translate to sharing the virtualized environment that your apps run in. The optional package’s app is still sandboxed in its own VFS by default.
How to Force Shared VFS/Registry Views
You have two reliable approaches to unify the environments:
1. Use a Shared Folder Extension (Recommended for Persistent Shared Data)
Configure your main package to expose a shared folder that both the main and optional packages can access. This creates a shared virtualized location that’s visible to all packages in the related set.
Step-by-Step:
- Add a
windows.sharedFolderextension to your main package’sPackage.appxmanifest:<Package ...> <Applications> <!-- Your main app entry --> </Applications> <Extensions> <uap:Extension Category="windows.sharedFolder"> <uap:SharedFolder Name="CommonAppData"> <uap:Folder>SharedData</uap:Folder> </uap:SharedFolder> </uap:Extension> </Extensions> </Package> - In both your main and optional package apps, access this shared folder via the package’s installed location:
This folder will be virtualized identically for both packages, ensuring consistent file access.// C# example for UWP/WPF apps var sharedFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("SharedData");
2. Launch Optional Package Apps in the Main Package’s Virtual Environment
If you need full access to the main package’s entire VFS (not just a shared folder), you can launch the optional package’s executable within the main package’s virtualized context using PowerShell or a custom launcher.
Example PowerShell Command:
Invoke-CommandInDesktopPackage -PackageFamilyName "YourMainPackageFamilyName" -Command "C:\Program Files\WindowsApps\YourOptionalPackageFullName\OptionalApp.exe"
Replace YourMainPackageFamilyName and YourOptionalPackageFullName with the actual values from Get-AppxPackage.
For a production scenario, you can build a lightweight launcher app in the main package that spawns the optional package’s executable using the same virtual environment (via the CreateProcessFromApp Win32 API).
3. Verify the Shared Environment
To confirm the VFS is shared:
- Create a test file in the main package’s VFS (e.g.,
C:\Program Files\WindowsApps\MainPackage\VFS\ProgramFilesX64\Test.txt). - Launch the optional package app using one of the methods above, then check if it can read/write to that file.
- Use Process Explorer to inspect the optional app’s process—you’ll see it’s associated with the main package’s virtualization context.
内容的提问来源于stack exchange,提问作者Hammerite

