7

What's up with my launch condition? It's supposed to prevent the x86 installer from running on a 64-bit system, but it seems to have no effect.

<!-- Launch Condition to check that x64 installer is used on x64 systems -->
<Condition Message="64-bit operating system was detected, please use the 64-bit installer.">
  <![CDATA[VersionNT64 AND ($(var.Win64) = "no")]]>
</Condition>

var.Win64 is derived from the MSBuild variables like this:

  <!-- Define platform-specific names and locations -->
  <?if $(var.Platform) = x64 ?>
  <?define ProductName = "$(var.InstallName) (x64)" ?>
  <?define Win64 = "yes" ?>
  <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
  <?define PlatformCommonFilesFolder = "CommonFiles64Folder" ?>
  <?else ?>
  <?define ProductName = "$(var.InstallName) (x86)" ?>
  <?define Win64 = "no" ?>
  <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
  <?define PlatformCommonFilesFolder = "CommonFilesFolder" ?>
  <?endif ?>

I would like to solve my problem, but I'd also be interested to hear about strategies for troubleshooting this type of problem.

Tim Long
  • 13,508
  • 19
  • 79
  • 147

1 Answers1

9

According to the LaunchCondition table definition:

Expression that must evaluate to True for installation to begin.

Your condition consists of 2 parts: the first one evaluates at install time, the other one evaluates at build time. So, for x86 package the second part of condition will evaluate to "no" = "no" at build time, which obviously gives True at install time. And the first part - VersionNT64 - is defined (and thus, True) on x64 machines. That's why the whole condition is True and installation starts.

You can rewrite your condition as follows:

<Condition Message="64-bit operating system was detected, please use the 64-bit installer.">
  <?if $(var.Win64) = "yes" ?>
    VersionNT64
  <?else?>
    NOT VersionNT64
  <?endif?>
</Condition>

Hence, in 64-bit package the condition will be just VersionNT64, and will pass and start install. Form x86 package the condition will be NOT VersionNT64, which will obviously fail on 64-bit, but start on 32-bit.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • 1
    Note that the 64-bit package won't get to LaunchConditions before it aborts on a 32-bit system. So there's not really any need to make the message for that case better. – Michael Urman Aug 12 '11 at 14:05
  • @Yan, thank you for the reply. Let me be absolutely sure I understand you correctly, I think what you're saying is that I just made a simple logic error in my condition. Now that I look at it, I think I see my mistake. As well as your re-written version, would I be right in thinking that just changing the "no" to "yes" would also fix the problem? So, I would be left with: `VersionNT64 AND ($(var.Win64) = "yes")` – Tim Long Aug 13 '11 at 04:18
  • 1
    @Tim, I'm not sure you got the point right. Look, adding an expression as in your second part is the same as adding an install-time constant, True or False, because it evaluates at build time. For x86 package you'll end up with `VersionNT64 AND "no" = "yes"`, which is `VersionNT64 And False`, which will give you `False` disregarding the value of `VersionNT64`. Hence, you'll never pass this launch condition. Don't make a build time variable a part of the install time expression - instead, let it influence the condition, like e.g. using if/else preprocessor statements. – Yan Sklyarenko Aug 13 '11 at 20:29
  • 1
    Right! Got it. I'm using your suggested re-write and it works well for me. Thanks for taking the time to answer my question, I really appreciate it. – Tim Long Aug 14 '11 at 16:26