JPackage update "PATH" environment variable

Viewed 386

when creating an installer (eg .msi) with jpackage, is there any way to update the PATH environment variable? This is quite important for console utilities.

Did not see anything about it in the jpackage documentation. Maybe one day it will be supported... but, meanwhile, is there any workaround? (I mean, besides asking the users to manually update PATH by themselves...)

1 Answers

Is It Possible?

YES.

Jpackage provides the ability to further customize the installer package built with WiX.

You'll have to use --resource-dir for that, as explained in Packaging Tool User's Guide.

Get Default main.wxs

Use the following command:

jpackage --input my_app [...] --temp "some/dir"

You'll have the following file structure generated:

\some\dir
   \config
      my_app.ico
      my_app.properties
      main.wxs
      MsiInstallerStrings_en.wxl
      MsiInstallerStrings_ja.wxl
      MsiInstallerStrings_zh.wxl
      overrides.wxi
   \images
   \wixobj

Copy the main.wxs file into the directory of choice, e.g. my_resource_dir.

You aren't gonna need anything else, so you can safely delete it as well as the installation package generated.

Change main.wxs to Append Your Installation Directory to the Path Variable

Change lines in my_resource_dir/main.wxs:

<Feature Id="DefaultFeature" Title="!(loc.MainFeatureTitle)" Level="1">
  <ComponentGroupRef Id="Shortcuts"/>
  <ComponentGroupRef Id="Files"/>
  <ComponentGroupRef Id="FileAssociations"/>
</Feature>

to:

<Feature Id="DefaultFeature" Title="!(loc.MainFeatureTitle)" Level="1">
  <ComponentGroupRef Id="Shortcuts"/>
  <ComponentGroupRef Id="Files"/>
  <ComponentGroupRef Id="FileAssociations"/>
  <Component Id="pathEnvironmentVariable" Guid="{YOUR_GUID}" KeyPath="yes" Directory="TARGETDIR">
    <Environment Id="MyPathVariable" Name="Path" Value="[INSTALLDIR]" Action="set" System="no" Permanent="no" Part="last" Separator=";" />
  </Component>
</Feature>

Make sure to replace YOUR_GUID with the GUID generated with the generator tool. For example: [...] Guid="{607ea423-79e0-4866-9ed7-62005b88d225}"

Create the Installer that Appends to Path:

Run the following command:

jpackage --input my_app [...] --resource-dir "my_resource_dir" --verbose

In the log output you should see something similar to:

[...] Using custom main.wxs file [...]

Result

The installer built now appends your INSTALLDIR to the Path on installation and removes it during uninstall.

Related