Detecting ASP.NET MVC 1.0 using WiX

Once you are done writing your MVC application you will probably start looking at deploying it. In many instances, creating a simple web deployment project should suffice, but if you decide to distribute your application using an MSI then you will most likely need to determine whether MVC is installed on the target system. The simplest way to do this when using WIX is to specify a launch condition. For MVC 1.0 there are two options at your disposal to create a property for a launch condition.

Option 1: Use the registry

When MVC is installed it creates a key in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\ASP.NET MVC 1.0 called InstallPath. This value can be read using the <RegistrySearch> element and stored in a property. The key won’t be present unless the installation of MVC completed successfully.

All that remains to be done is to define a launch condition that uses this property. Remember that a launch condition specifies the condition under which an installation should continue, not the condition under which it should fail.

   1: <?xml version='1.0' encoding='windows-1252'?>
   2: <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
   3:   <Product Name='Foo 1.0' Id='8A94F114-6F67-4728-8B5E-B4EC115AF3AF'
   4:     UpgradeCode='B60B3A2A-C7BB-47F7-97C4-7D04332519D3'
   5:     Language='1033' Codepage='1252' Version='1.0.0' Manufacturer='Bar'>
   6:  
   7:     <Package Keywords='Installer' Description='Foo' Manufacturer='Bar'
   8:       InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
   9:       
  10:     <Condition Message='ASP.NET MVC 1.0 is required to proceed with the installation.'>
  11:       Installed OR ASP_NET_MVC_1_0
  12:     </Condition>
  13:     
  14:     <Property Id='ASP_NET_MVC_1_0'>
  15:       <RegistrySearch Id='MVC_InstallDir' Type='directory' Root='HKLM'
  16:                       Key='SOFTWARE\Microsoft\ASP.NET\ASP.NET MVC 1.0'
  17:                       Name='InstallPath'/>
  18:     </Property>    
  19:  
  20:   </Product>
  21: </Wix>

Option 2: Use the assembly file version

Apart from installing into the GAC and creating a native image for System.Web.Mvc, we also drop the DLL along with the XML comments under Program Files\Microsoft ASP.NET\ASP.NET MVC 1.0\Assemblies. If you don’t want to use the registry option you can define your property using a <FileSearch> element. You can use the code from the first example and just replace the <Condition> and <Property> elements with the code below.

   1: <Condition Message='ASP.NET MVC 1.0 is required to proceed with the installation.'>
   2:   Installed OR ASP_NET_MVC_1_0_DLL
   3: </Condition>
   4:  
   5: <Property Id='ASP_NET_MVC_1_0_DLL'>
   6:   <DirectorySearch Id='MVC_DLL_DIR' Path='[ProgramFilesFolder]\Microsoft ASP.NET\ASP.NET MVC 1.0\Assemblies'>
   7:     <FileSearch Id='MVC_DLL_FILE' Name='System.Web.Mvc.dll' MinVersion='1.0.40309'/>
   8:   </DirectorySearch>
   9: </Property>

VERY IMPORTANT: Notice that the code above is expecting a DLL with a minimum version of 1.0.40309. If you examine the properties of System.Web.Mvc.dll in Explorer you’ll notice that the version is in fact 1.0.40310. It’s just some weirdness in how the MinVersion attribute works. The explanation from MSDN states the following:

 

MinVersion
The minimum version of the file, with a language comparison. If this field is specified, then the file must have a version that is at least equal to MinVersion. If the file has an equal version to the MinVersion field value but the language specified in the Languages column differs, the file does not satisfy the signature filter criteria.
 
Note  The language specified in the Languages column is used in the comparison and there is no way to ignore language. If you want a file to meet the MinVersion field requirement regardless of language, you must enter a value in the MinVersion field that is one less than the actual value. For example, if the minimum version for the filter is 2.0.2600.1183, use 2.0.2600.1182 to find the file without matching the language information.

 

Compile and Run

The source code I’ve provided can be compiled and linked using candle and light. I’ve tested this under WiX 2.0, but haven’t tried it using WiX 3.0. You may also see the following ICE warnings when linking the wixobj file:

  • warning LGHT1076 : ICE40: Error Table is missing. Only numerical error messages will be generated.
  • warning LGHT1076 : ICE71: The Media table has no entries.

You can safely ignore these warnings. The installer code I provided is really stripped down to the bare minimum to produce an MSI that does absolutely nothing except trying to detect whether or not MVC 1.0 is installed. When you launch the MSI on a system without MVC you should see the message blow.

wixerror

 

4 Comments

  • @binghuan, yes you are correct. But since MVC is a 32-bit only MSI, Windows Installer will make sure that it gets the registry keys from the correct hive as long as you don't use the Win64 attribute for the RegistrySearch element in your WiX code.

  • How can I detect is MVC 2.0 is installed, say the .net framework 4.0?

  • Hi Allen

    You can use the file version approach and check for a version of 2.0.50217. Note that this is only for the runtime. If for some reason you need to detect the tooling component you will need to handle the VS2008 and VS2010 cases separately.

    Don't rely on the fact that .NET 4 is installed, since MVC 2 is not part of the framework.

    Jacques

  • The majority of the eating plans supply the content you will need to make a well informed choice at the local connection to the web. Nevertheless would make botanical slimming soft gel an individual wonder how good every one of these eating habits unquestionably are.

Comments have been disabled for this content.