How does Files Redirection work with MSIX?

Written by Alex Marin · February 5th, 2020

#MSIX #APPDATA #USER INTERFACE

The purpose of this article is to show you how redirection works and how you can add your user files in the project using Advanced Installer GUI.

In the AppData Management in MSI/MSIX/APPV blog post, we have learned that for MSIX, user files reside in %localappdata%\packages\PublisherName.AppName_hash.

Let’s see how all this translates when you create a package, or when an application tries to write a file to a user location.

Building a project with Advanced Installer

Let’s start with a basic MSIX project.

  1. Open up Advanced Installer and from the Start Page select New > Installer > MSIX Package. Give it a name and choose the desired location for the project to be saved. Create in Files and Folders page, a folder named “TestRedirect” in both Application Data and Local Application Data.

    NoteThe purpose of this exercise is to simulate that the application needs to have specific files in %appdata% and %localappdata% user locations.

    This saves you from any additional actions needed to copy the necessary user files to %localappdata%\packages\PublisherName.AppName_hash. All you have to do is to create the folder structure as usual.
  2. Add the file MyRedirect1.txt to TestRedirect folder in Local Application Data and the MyRedirect2.txt to TestRedirect folder in Application Data.

We also created a simple executable called "Application.exe" which creates two files at runtime

  • AppDataFile.txt - created in %appdata%\TestRedirect\
  • LocalAppDataFile.txt - created in %localappdata%\TestRedirect\

The executable is placed directly into the "Application Folder".

Files folder

Next, we create an application in the Application Details page that points to our Application.exe.

With all the above changes, we save the project and click on Build in the top left corner.

ImportantDon’t forget to configure the build and sign the package before the build.

When installing the msix package, we uncheck "Launch when ready".

Knowing the AppData location from a previous article, we check and see that after installing this is created, in our case: %localappdata%\Packages\TestCompany.TestRedirection_r21n0w1rc5s2y\LocalCache.
But we notice that nothing is present there.

Now, if we start the application, we can see that in %localappdata%\Packages\TestCompany.TestRedirection_r21n0w1rc5s2y\LocalCache two more folders are created: Local and Roaming.

NoteLocal is the redirected folder for %localappdata%, and Roaming is the redirected folder for %appdata%.

Going next, if we navigate to %localappdata%Packages\TestCompany.TestRedirection_r21n0w1rc5s2y\LocalCache\Local\TestRedirect, we can see the two desired files, LocalAppDataFile.txt and MyRedirect.txt (both the file added within the MSIX package and the file created at runtime by our Application.exe executable).

The same applies for the Roaming folder in %localappdata%\Packages\TestCompany.TestRedirection_r21n0w1rc5s2y\LocalCache\Roaming\TestRedirect. The two files, AppDataFile.txt and MyRedirect2.txt are present.

NoteThis means that during the first launch, the user data is copied from C:\Program Files\WindowsApps\TestCompany.TestRedirection_1.0.0.0_x64__r21n0w1rc5s2y\VFS\ to %localappdata%\packages\PublisherName.AppName_hash\LocalCache.

Vfs

If an executable needs to write any user data in the form of files or folders, these will be automatically redirected to %localappdata%\packages\PublisherName.AppName_hash\LocalCache during execution.

Local cache

Conclusion

When building an MSIX project, the steps are not so different from an MSI. The user data is automatically copied during the first launch, so you don’t need to worry about how to place it on all users.

Also, you must keep in mind that everything an application normally places in the user profile is automatically redirected.

This is great because this way, you have a clean uninstallation and everything is deleted from the machine.

ImportantMore on the MSIX subject is available here.

Subscribe to Our Newsletter

Sign up for free and be the first to receive the latest news, videos, exclusive How-Tos, and guides from Advanced Installer.

Comments: