Setting Wix shortcut with environment variable wor

2019-08-02 18:15发布

问题:

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?

回答1:

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



回答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%.



标签: wix wix3.6