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'
5: Language='1033' Codepage='1252' Version='1.0.0' Manufacturer='Bar'>
7: <Package Keywords='Installer' Description='Foo' Manufacturer='Bar'
8: InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
10: <Condition Message='ASP.NET MVC 1.0 is required to proceed with the installation.'>
11: Installed OR ASP_NET_MVC_1_0
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'
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
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'/>
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:
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.