7

How to use any type of Environment Variable in MSIX

 3 years ago
source link: https://www.advancedinstaller.com/environment-variables-types-in-msix.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to use any type of Environment Variable in MSIX

Written by Alex Marin · December 21st, 2020

In a previous article we had a look on how Environment Variables work with MSIX. We now know that in MSIX, Environment Variables are redefined as AppExecutionAlias.

There's a limitation when using AppExecutionAlias, which is that by default, you can only reference Environment Variables pointing to executables -- leaving other types of Environment Variables out.

Noting this, Advanced Installer added support for all types of Environment Variables in your MSIX package.

How to Configure Environment Variables

To configure an Environment Variable in Advanced Installer, navigate to the Environment page.

There, you can add, edit or remove any Environment Variables from your package. In our case we created a variable called TESTVARIABLE, which points to C:\temp.

environment-tools.png

NoteIf you repackage an installation, all the environment variables detected during the operation will appear within this Environment page.

The Differences Between Environment Variables and AppExecutionAlias

With Advanced Installer you can create standard Environment Variables using an additional predefined fixup in our Package Support Framework.

The fixup is applied automatically when an Environment Variable is detected in the package (with no additional input required for the user).

During the launch of the application, we emulate the Environment Variable so that the executable can detect it.

The difference between Environment Variables and the AppExecutionAlias is that the AppExecutionAlias is declared globally on the system so it can be accessed by external applications while the Environment Variable is emulated only within the MSIX container.

For example, if an AppExecutionAlias is defined for a HelloWorld.exe, when you open up CMD and type HelloWorld.exe, the application will launch.

This won’t happen with the Environment Variables added through the Environment Page, since they are only emulated inside the MSIX container, and cannot be accessed externally.

If we create a standard MSIX package, add the above mentioned variable, and run the application, it will detect the Environment Variable.

detect-environment-variables.gif

NoteKeep in mind that if we search for this variable on the system, it will not be found.

The Expected Behavior of Environment Variables

The Environment Variable Edit Dialog, allows various operations and behaviors to be applied to an Environment Variable. This will look familiar to you if you worked with MSI. We wanted to follow the same logic with MSIX for operations and behaviors related to Environment Variables.

For example, if an Environment Variable is already present on the system, and we choose to update that variable, this will overwrite it in the MSIX container.

NoteThe Environment Variable on the system will not be modified. This will be overwritten only in the MSIX container of your application.

You can also append the value to an existing Environment Variable (like PATH), this change will also apply only inside the container of your application.

So keep in mind that all the settings you had available for the MSI technology are still valid in the MSIX technology, with the exception that the environment variables form an MSIX package are visible only inside the container of that application and not for other applications installed on the machine.

Conclusion

The main thing to remember is that AppExecutionAlias is not the same with Environment Variables. Also, Environment Variables are only emulated inside the MSIX container, and cannot be accessed from the system.

With Advanced Installer's additional predefined fixups, you can overcome the limitations set by the AppExecutionAlias and get support for all Environment Variables in your MSIX packages and applications.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK