Thoughts about setup and deployment issues, WiX, XNA, the .NET Framework and Visual Studio
All postings are provided AS IS with no warranties, and confer no rights. Additionally, views expressed herein are my own and not those of my employer, Microsoft.
Question:
I am creating an MSI-based setup using WiX. One of the files that I am installing is authored like this:
<DirectoryRef Id="MyDirectory"> <Component Id="MyComponent" Guid="PUT-GUID-HERE" DiskId="1"> <File Id="MyAssembly" Name="MyAssembly.dll" Assembly=".net" KeyPath="yes" Source="MyAssembly.dll" /> </Component></DirectoryRef>
When I create an MSI and install it, I see MyAssembly.dll gets installed to the global assembly cache (GAC), but it does not get installed to MyDirectory.
How can I author my MSI using WiX so that it will install to both the GAC and a local directory?
Answer:
When you use the attribute Assembly=".net" for a file in WiX, it will create entries in the MsiAssembly and MsiAssemblyName table for this component and mark it as a GAC component. That means that the file will only be installed to the GAC by this component, and it will not install to the directory that the component is a child of. That directory will only be used by Windows Installer to stage a copy of that file when creating and administrative install point.
If you need to install the file to both the GAC and the local file system, you will need to author a second component that contains another copy of this file and make sure to not include Assembly=".net" in that second component.
Heath Stewart has posted some sample WiX syntax in this blog post that can be used as a guide for authoring components to install a file to both the GAC and the local file system. I want to call out a couple of key points about this scenario:
A file created with DuplicateFile won't be associated with a component and therefore can't be serviced or repaired, IIRC. Better to list the file twice.