15

I currently using the following markup in my WiX installer project to check if .NET Framework 4.5 or greater is installed.

<PropertyRef Id="NETFRAMEWORK45" />

<Condition Message="$(var.ProductName) requires .NET Framework 4.5 or higher.">
  <![CDATA[Installed OR (NETFRAMEWORK45 >= "#393295")]]>
</Condition>

How can I check for .NET Framework 4.6.1 and above?

I'm using WiX 3.10.2.2516.

dommer
  • 19,610
  • 14
  • 75
  • 137
  • the missing link about including the `WixNetFxExtension`: https://stackoverflow.com/a/27946359/492 - especially in command line things but also in VS projects – CAD bloke Jul 24 '18 at 07:14

5 Answers5

21

How about:

<PropertyRef Id="WIX_IS_NETFRAMEWORK_461_OR_LATER_INSTALLED" />
<Condition Message="$(var.ProductName) requires .NET Framework 4.6.1 or higher.">
  <![CDATA[Installed OR WIX_IS_NETFRAMEWORK_461_OR_LATER_INSTALLED]]>
</Condition>
ProfNimrod
  • 4,142
  • 2
  • 35
  • 54
  • 6
    You can always take a look at the actual wix source for netfxextension to see any other properties that may be of use. https://github.com/wixtoolset/wix3/blob/develop/src/ext/NetFxExtension/wixlib/NetFx461.wxs Also very helpful when trying to emulate something wix does but for another purpose since you can see the actual code they use. – Brian Sutherland May 23 '16 at 22:02
  • 1
    There's a WIX_IS_NETFRAMEWORK_46_OR_LATER_INSTALLED, but not a WIX_IS_NETFRAMEWORK_461_OR_LATER_INSTALLED. – dommer May 24 '16 at 07:42
  • OK. As mj2008 notes, it looks like this is available in a newer build so will presumably end up in the stable release soon. – dommer May 24 '16 at 09:55
  • 2
    It's not in the stable release as of this time, and it doesn't look like it'll be integrated into 3.10.x (nightly 3.10.x builds don't have it, just 3.11.x). See my answer below for a work around. – Dan Field Sep 08 '16 at 02:44
12

I'm afraid none of the above worked for me. Or perhaps I didn't quite understand how to implement the suggestions.

What worked for me however was my previous check for .Net Framework 4.5.1 requirement similar to your check for 4.5.

Simply changing the version to the target .Net Framework version number to the required one, found here: https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx, worked for me.

I ended up with this:

<PropertyRef Id="NETFRAMEWORK45"/>
<Condition Message="This application requires .NET Framework 4.6.1. Please install the .NET Framework then run this installer again.">
    <![CDATA[Installed OR (NETFRAMEWORK45 >= "#394254")]]>
</Condition>

P.S. I implemented the change today, so the next few days of testing will reveal to me whether it works or not. Will update my comment when I have some results to share.

P.P.S. Testing has succeeded my side. The installer successfully fails on environments which do not have .Net Framework 4.6.1 installed and installs successfully on those which do. (Also: Thanks @RamenChef, for editing my post :+1:)

Sascha
  • 189
  • 3
  • 11
  • I get the error 'Property:NETFRAMEWORK45' in section 'Product:*'. is missing. – rollsch Nov 07 '17 at 04:56
  • 1
    Have you included the following at the top in the Wix xml node?: `code`(xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension") what it looks like for me: `code`( your wix xml ) – Sascha Nov 08 '17 at 05:55
  • Ah I needed to add a refernece to WixNetFxExtension.dll for the xml reference to work. Thanks for the reply. – rollsch Nov 09 '17 at 00:25
  • The version number for .NET 4.6 and newer is different on Windows 10 from previous versions of Windows. – Damian Dixon Apr 26 '18 at 09:56
  • That is correct. You can find the version numbers on the Microsoft weblink as mentioned in the link mentioned in my solution. Here it is again: https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx – Sascha May 08 '18 at 07:45
8

Update: The current stable version of WiX now has this integrated; this answer may be of interest if, for some reason, you're using an older version (e.g. 3.10.3, which was latest when this was originally written)


The current release version of WiX (3.10.3) doesn't support this property, nor does the current 3.10.x nightly build (3.10.3.3007) - it does look like the 3.11.0.960 does support it, but that build isn't labeled as production ready so it's not an option for my scenario.

What I ended up doing was grabbing the source for NetFx461.wxs (here), and adding it to my 3.10 release project after modifying it slightly (see below). After that I was able to use the property. You could do similar changes for 4.6.2 if needed.

Here's the file:

<?xml version="1.0" encoding="utf-8"?>
<!--
  <copyright file="NetFx461.wxs" company="Outercurve Foundation">
    Copyright (c) 2004, Outercurve Foundation.
    This software is released under Microsoft Reciprocal License (MS-RL).
    The license and further copyright text can be found in the file
    LICENSE.TXT at the root directory of the distribution.
  </copyright>
-->
<!--<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">-->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension" xmlns:wxs="http://wixtoolset.org/schemas/v4/wxs">


  <!--
        .NET Framework installation state properties

        Official documentation can be found at the following location:

           .NET Framework 4.5/4.5.1/4.5.2/4.6/4.6.1 - http://msdn.microsoft.com/en-us/library/w0x726c2(v=vs.110).aspx
    -->

  <?define NetFx461MinRelease = 394254 ?>
  <?define NetFx461WebLink = http://go.microsoft.com/fwlink/?LinkId=671728 ?>
  <?define NetFx461RedistLink = http://go.microsoft.com/fwlink/?LinkId=671743 ?>

  <Fragment>
    <PropertyRef Id="WIXNETFX4RELEASEINSTALLED" />
    <Property Id="WIX_IS_NETFRAMEWORK_461_OR_LATER_INSTALLED" Secure="yes" />
    <SetProperty Id="WIX_IS_NETFRAMEWORK_461_OR_LATER_INSTALLED" Value="1" After="AppSearch">
      WIXNETFX4RELEASEINSTALLED >= "#$(var.NetFx461MinRelease)"
    </SetProperty>
  </Fragment>

  <Fragment>
    <util:RegistrySearchRef Id="NETFRAMEWORK45"/>

    <WixVariable Id="NetFx461WebDetectCondition" Value="NETFRAMEWORK45 &gt;= $(var.NetFx461MinRelease)" Overridable="yes" />
    <WixVariable Id="NetFx461WebInstallCondition" Value="" Overridable="yes" />
    <WixVariable Id="NetFx461WebPackageDirectory" Value="redist\" Overridable="yes" />

    <PackageGroup Id="NetFx461Web">
      <ExePackage
          InstallCommand="/q /norestart /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx461FullLog].html&quot;"
          RepairCommand="/q /norestart /repair /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx461FullLog].html&quot;"
          UninstallCommand="/uninstall /q /norestart /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx461FullLog].html&quot;"
          PerMachine="yes"
          DetectCondition="!(wix.NetFx461WebDetectCondition)"
          InstallCondition="!(wix.NetFx461WebInstallCondition)"
          Id="NetFx461Web"
          Vital="yes"
          Permanent="yes"
          Protocol="netfx4"
          DownloadUrl="$(var.NetFx461WebLink)"
          LogPathVariable="NetFx461FullLog"
          Compressed="no"
          Name="!(wix.NetFx461WebPackageDirectory)NDP461-KB3102438-Web.exe">
        <RemotePayload 
          CertificatePublicKey="52868DFCA6E3AF2632389E6C1EE7D0468D3797D0" 
          CertificateThumbprint="3BDA323E552DB1FDE5F4FBEE75D6D5B2B187EEDC" 
          Description="Microsoft .NET Framework 4.6.1 Setup" 
          Hash="EE88B05232F43B517D4A368F7EE5065CDE7F67FA" 
          ProductName="Microsoft .NET Framework 4.6.1" 
          Size="1424328" 
          Version="4.6.1055.0" />
      </ExePackage>
    </PackageGroup>
  </Fragment>

  <Fragment>
    <util:RegistrySearchRef Id="NETFRAMEWORK45"/>

    <WixVariable Id="NetFx461RedistDetectCondition" Value="NETFRAMEWORK45 &gt;= $(var.NetFx461MinRelease)" Overridable="yes" />
    <WixVariable Id="NetFx461RedistInstallCondition" Value="" Overridable="yes" />
    <WixVariable Id="NetFx461RedistPackageDirectory" Value="redist\" Overridable="yes" />

    <PackageGroup Id="NetFx461Redist">
      <ExePackage
          InstallCommand="/q /norestart /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx461FullLog].html&quot;"
          RepairCommand="/q /norestart /repair /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx461FullLog].html&quot;"
          UninstallCommand="/uninstall /q /norestart /ChainingPackage &quot;[WixBundleName]&quot; /log &quot;[NetFx461FullLog].html&quot;"
          PerMachine="yes"
          DetectCondition="!(wix.NetFx461RedistDetectCondition)"
          InstallCondition="!(wix.NetFx461RedistInstallCondition)"
          Id="NetFx461Redist"
          Vital="yes"
          Permanent="yes"
          Protocol="netfx4"
          DownloadUrl="$(var.NetFx461RedistLink)"
          LogPathVariable="NetFx461FullLog"
          Compressed="no"
          Name="!(wix.NetFx461RedistPackageDirectory)NDP461-KB3102436-x86-x64-AllOS-ENU.exe">
        <RemotePayload
          CertificatePublicKey="52868DFCA6E3AF2632389E6C1EE7D0468D3797D0" 
          CertificateThumbprint="3BDA323E552DB1FDE5F4FBEE75D6D5B2B187EEDC" 
          Description="Microsoft .NET Framework 4.6.1 Setup" 
          Hash="83D048D171FF44A3CAD9B422137656F585295866" 
          ProductName="Microsoft .NET Framework 4.6.1" 
          Size="67681000" 
          Version="4.6.1055.0" />
      </ExePackage>
    </PackageGroup>
  </Fragment>
</Wix>

Add that (say as NetFx461.wxs) to your WiX installer project and you'll have access to the desired properties.

Dan Field
  • 20,885
  • 5
  • 55
  • 71
  • It does not work for me on Windows 7 x86. When I run installer it behaves as if .NET 4.6.1 is not installed. The same on Win10 x64 – sergtk Dec 08 '16 at 00:11
  • What are the registry values for the keys it's looking up? Also, are you sure 4.6.1 is installed? – Dan Field Dec 08 '16 at 02:16
  • Yes, I installed .NET 4.6.1 and my check in msi works fine now. I implemented solution from @Sascha answer and it works fine. The answer above does not work for me. Your answer looks correct, but actually it does not work for me. I didn't drill into details, because I found another solution. – sergtk Dec 10 '16 at 21:02
4

The WIX_IS_NETFRAMEWORK_461_OR_LATER_INSTALLED value was implemented by FabienLavocat and merged in a week ago according to the GitHub pull request

mj2008
  • 6,647
  • 2
  • 38
  • 56
  • I'm having trouble finding which release it has been integrated in. Do you know which release it is? Thanks. – Sync Aug 15 '16 at 17:51
  • 1
    It's not in the current stable production build at this point - see my answer for a work around. – Dan Field Sep 08 '16 at 02:43
0

Here is my solution for this problem. I use it to check for .NET 4.7 but it should work for all .NET 4.5+ framework versions.

See https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#net_b for a list of valid revision numbers.

I use a registry search to set the value of a property to the revision of the .NET 4.x framework. Later I use this property in the well known way to check the launch condition:

<?define NetFx47MinRelease = 460798 ?>
<Property Id="NETFRAMEWORK47" Value="0" Secure="yes">
    <RegistrySearch
        Id="RegSearch"
        Root="HKLM"
        Key="SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
        Name="Release"
        Type="raw" />
</Property>

<Condition Message="PPG OnBoard requires .NET Framework 4.7 installed.">
    <![CDATA[NETFRAMEWORK47 >= "#$(var.NetFx47MinRelease)"]]>
</Condition>

Unfortunately in this situation RegistrySearchreturns the DWORD value prefixed with a '#' character which made it unusable in a "greater than" condition in my first tests. Use the exact "#$(var.NetFx47MinRelease)" syntax to be able to compare for "greater than".

Andreas
  • 1,551
  • 4
  • 24
  • 55