How to Set Up an Environment Variable in MSIX to Directory and File Paths
Environmental variables, as their name implies, are variables that specify the environment in which a program runs.
The data in an environment variable is always saved as a string, and can be used by the operating system itself or the programs installed on the device.
In this article, we will go through the process of overcoming one of the MSIX limitations: setting up a traditional environment variable to a folder/directory path.
First, let’s see what are the two types of environmental variables:
1. User Environment Variables – they can be accessed only by the current logged on user
2. System Environment Variables – they can be accessed and are globally available to all users.

On the other hand, both User and System Environment Variables can store Directory/Folder paths and File paths.

Environment Variables and MSIX limitation with App Execution Aliases
When Microsoft released MSIX, they didn’t bring over the environment variables. However, you still can achieve pretty much the same thing by using the App Execution Aliases.
The issue is that with the App Execution Aliases you can specify only a file path target, not a directory/folder path.
Check out our MSIX - AppExecutionAlias article, if you want to find out more about App Execution Aliases and how to set it up within your MSIX package.
This limitation could turn out to be a dead end if you need to convert a legacy Win32 app to MSIX and the application requires an environment variable from a specific directory/folder path in order to work as designed.
How can you overcome this? Let's take a look.
Inject PSF EnvVarFixup with the MSIX Packaging Tool
Starting with version 1.2022.1003.0, you can use the MSIX Packaging Tool to inject the EnvVarFIxup.
To do this:
1. Go to the “PSF Fixups” page.
2. Select the “Environment Variable Fixup” and configure it accordingly.

Advanced Installer Solution to MSIX Environment Variable Limitations
In Advanced Installer, we developed our own support for this kind of limitation without the need to write any code or manually inject the Package Support Framework into the MSIX package.
All you need to do is go to the Environment page and set up your Environment Variable as you would normally do for MSI packages.
So, if you want to set up a System Variable called MYAPP, you need to point it to the installation folder - in our scenario APPDIR.

And that’s all.
Now, if you build and install the MSIX package on a machine, you can see that the environment variable (MYAPP) you set up earlier from the Environment page is visible within the MSIX container.
You can easily do that by using Hover, a free utility tool developed by the team behind Advanced Installer that helps you run natively installed applications inside the MSIX container. It is included in the “Tool” section of Packit.
Using it is straightforward:
1. Open Packit and navigate to the Tool section.
2. Select “Run inside MSIX container”.

3. Select the target MSIX package from the left side pane and then double-click the program you want to launch within the MSIX container from the right side pane.

That’s it! A new Command Prompt window will open within the container environment. To verify everything is working correctly, just type set in the command line—you’ll see that the MYAPP environment variable is properly loaded inside the container.

Furthermore, we also integrated all MSI Environment Variables support into MSIX – meaning that you can now update (prepend or append) an existing Environment Variable (e.g. Path).
Append the Path Environment Variable in Advanced Installer
The process is similar to our solution for MSI environment variables.
This time you need to choose Append for the Behavior option – in our case we want to append the Path Environment Variable.

And now, as you can see, the Path Environment Variable got appended with the installation folder for our application.

You can use the same solution to declare and set up an Environment Variable targeting a file path.
Conclusion
Now you know how to declare and set up a traditional Environment Variable within MSIX packages – no coding or needing to manually inject the Package Support Framework.
Keep in mind that Environment Variables declared this way are visible only within the MSIX container, but that will do the trick and help you fix this specific MSIX limitation.
Thanks to its easy-to-use GUI, Advanced Installer comes up with solutions constantly to help you overcome MSIX limitations.
Let us know if there's any other MSIX limitation that you'd like us to write about.