ExeFileShortcut set working directory to %TEMP%

Sep 6, 2016 at 5:24 PM
I have the following code which works great to install my application. However, I need to set the shortcut to the .exe to have the working directory (or "Start in:" on shortcut properties of the icon) set to %TEMP% (which changes on each client PC). I can set the working directory to pretty much any value but %TEMP% or %TMP%. How can I set the working directory to this value?

Thanks.
var project =
      new Project("MYClient",      
          new Dir(@"C:\ZZZ\BBBXXX\CCC\bin\",
          new File(@"Files\XXX\1.dll"),
          new File(@"Files\XXX\2.dll"),
          new File(@"Files\XXX\3.bmp"),
          new File(@"Files\XXX\4.dll"),
          new File(@"Files\XXX\5.dll"),
          new File(@"Files\XXX\6.dll"),
          new File(@"Files\XXX\7.exe")),          
                            
          new Dir(@"%Desktop%",                
            new ExeFileShortcut("{Shortcut}",@"[INSTALLDIR]7.exe",@"{Options}") {  IconFile = @"c:\Temp\logo-Icon.ico" , WorkingDirectory=@"%TEMP%"  }
          ));
              
       project.Version = new Version("8.13.0.{Revision}");
  project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default;

  project.UI = WUI.WixUI_ProgressOnly;
  project.GUID = new Guid("79049b26-354f-425f-a938-3ca77183fb13");
  
  project.PreserveTempFiles = true;
  
  Compiler.BuildMsi(project);
Sep 7, 2016 at 5:17 AM
There are a few things that prevents your code from working. The temporary directory WiX property name is TempFoder thus you need to encode it as below:
WorkingDirectory="%TempFolder%"
//or 
WorkingDirectory="[TempFolder]"
//or
WorkingDirectory="TempFolder"
Though I just added to support for %Temp% as well and it will be available in the next release.

The second problem is MSI/WiX but not Wix# related. The WiX Shortcut element must be a Directory or Property identifier (not path). Thus if you have in your wxs file WorkingDirectory="TempFolder" then it is exactly what you need. However there is a problem here and I will illustrate it with the code. This is a fragment from Shortcut sample that has been modified to set working directory for an application shortcut and for the exe (msiexe.exe) shortcut:
new File(@"AppFiles\MyApp.exe",
    new FileShortcut("MyApp", "INSTALLDIR"), //INSTALLDIR is the ID of "%ProgramFiles%\My Company\My Product" 
    new FileShortcut("MyApp", @"%Desktop%")
    {
        IconFile = @"AppFiles\Icon.ico",
        WorkingDirectory = "%Temp%"
    }),
new ExeFileShortcut("Uninstall MyApp", "[System64Folder]msiexec.exe", "/x [ProductCode]")
{
    WorkingDirectory = "%Temp%"
}),
This would lead to the correct wxs for both shortcuts:
<Shortcut Id="INSTALLDIR.Uninstall_MyApp" WorkingDirectory="TempFolder" Target="[System64Folder]msiexec.exe" Arguments="/x [ProductCode]" Name="Uninstall MyApp.lnk" />
<Shortcut Id="Shortcut.MyApp.exe.MyApp.1" WorkingDirectory="TempFolder" Directory="DesktopFolder" Name="MyApp.lnk" Icon="IconFile1_Icon.ico" IconIndex="0" />
This also produces correct msi table content:
Image
However for some unknown reason the final result is mixed. One shortcut gets correct working dir another one doesn't:
Image

Meaning that even after fixing your code the final result is not guaranteed.

Cheers
Marked as answer by abcaldef on 9/7/2016 at 3:43 PM
Sep 7, 2016 at 11:43 PM
Awesome. Thanks so much. I think that got it.