1

Part of my application needs to read a config file, which I keep in the same directory as my application's exe. My issue is that the shortcuts created by WiX don't find this file.

I can create my shortcuts post install, and they work, but I would rather fix this issue instead of doing that.

This is what my component looks like:

<Component Id="MyApp.exe" Guid="G-U-I-D">
    <File Id="MyApp.exe" Name="MyApp.exe" Source="$(var.MyApp_TargetDir)MyApp.exe">
      <Shortcut Id="DesktopShortcut" Directory="DesktopFolder" Name="My Application" Icon="Icon.ico" Advertise="yes" />
      <Shortcut Id="StartMenuShortcut" Directory="ProgramMenuFolder" Name="My App" Icon="Icon.ico" Advertise="yes" />
    </File>
</Component>
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Epidilius
  • 21
  • 3

1 Answers1

0

UPDATE: If I understand your comment correctly, I am wondering if you simply do not set the shortcut's WorkingDirectory attribute?

WiX Markup Sample:

<Directory Id="MyDir" Name="My Dir">

  <Component Id="My.exe" Feature="Main">
    <File Source="My.exe">
      <Shortcut Id="DesktopShortcut"
                Directory="DesktopFolder"
                Name="My Product"
                Advertise="yes"

                WorkingDirectory="MyDir">
       </Shortcut>
    </File>
  </Component>

</Directory>

Shortcut Properties:

Shortcut Properties


If this is a settings file that you intend to write to you should put it in the user profile so that it is writeable for the launching user. Your application.exe file should be able to find the config file regardless if it is in your application installation folder or in the user profile?

C# mockup (should use Path.Combine, but this is just for illustration):

string filepath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\MyFolder\MyFile.xml";

Is there a specific need to specify the file path in the shortcuts?


Some Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Not a settings file, it's a read only xml file. And to clarify, my application.exe finds it. I can, after installing, create shortcuts for my application and put them anywhere on my PC, and launching through a shortcut works. It's just when I use the shortcuts created during the installation process that the issue comes up. – Epidilius Sep 25 '18 at 12:50
  • Please check the new top section of the answer - see if that helps. – Stein Åsmul Sep 25 '18 at 20:48