1

I'm trying to create a shortcut in WIX with teh following WorkingDirectory:

<Shortcut Id="PowerShellShortcut" Name="$(var.PRODUCTNAME) Powershell Prompt" Description="$(var.PRODUCTNAME) Powershell Prompt" WorkingDirectory="%HOMEDRIVE%%HOMEPATH%" Target="[POWERSHELLEXE]" Arguments='-noexit -command "Import-Module [APPLICATIONFOLDER]Binaries\MA.dll | Out-Null"' />

When I try to build I get the following error:

Error 1 The Shortcut/@WorkingDirectory attribute's value, '%HOMEDRIVE%%HOMEPATH%', is not a legal identifier. Identifiers may contain ASCII characters A-Z, a-z, digits, underscores (_), or periods (.). Every identifier must begin with either a letter or an underscore.

Is there a workaround to set the literal string "%HOMEDRIVE%%HOMEPATH%" as the WorkingDirectory of a Shortcut?

John Simons
  • 4,288
  • 23
  • 41

2 Answers2

2

Per the documentation on the Shortcut Table, the working directory (WkDir) stores the name of a property that has the value you want stored into the shortcut. This property may be a DirProperty (i.e. also a reference into the Directory Table), or it may just hold a hardcoded string itself. If you want the final shortcut to have the literal text %HOMEDRIVE%%HOMEPATH%, then set your working directory to something like WKDIR_HOME which is the name of a property you have set to %HOMEDRIVE%%HOMEPATH%.

Michael Urman
  • 15,737
  • 2
  • 28
  • 44
  • Unfortunately, that doesn't fool WiX, so we're back to square one. – snips-n-snails May 30 '18 at 22:58
  • Then we would have two identical questions. I did as you described but WiX converted the property to a string literal and gave the same error about not allowing the `%` character. – snips-n-snails May 31 '18 at 03:08
  • 1
    Sorry, I was using a preprocessor variable, not a property. So I added a property `` and added it to my shortcut like this: `WorkingDirectory="WKDIR_HOME"` and now the shortcut's "Start in:" it shows "H:\" which is the value of %HOMEDRIVE%%HOMEPATH%, instead of the literal text `%HOMEDRIVE%%HOMEPATH%`. I guess that's good enough for now. – snips-n-snails May 31 '18 at 20:10
1

You cannot use environment variables like %HOMEDRIVE% in .wxs files. Instead of %HOMEDRIVE%%HOMEPATH%, try using $(env.HOMEDRIVE)$(env.HOMEPATH)

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
sohil
  • 508
  • 1
  • 3
  • 14
  • It doesn't like that because my %HOMEDRIVE% is "H:\". WiX says, "`Identifiers may contain ASCII characters A-Z, a-z, digits, underscores (_), or periods (.).`" – snips-n-snails May 30 '18 at 22:50