Using property in File element's Source property in WiX - wix

I am trying to use Property value in Source attribute of File element, but getting this error:
error LGHT0103 : The system cannot find the file '[MYPROPERTY]'
Here is how property defined and used:
<Property Id="MYPROPERTY" Secure="yes" Value="myfile.xml" />
...
<File Id="MyFileId" Name="myfile.xml" Source="SubFolder\[MYPROPERTY]" KeyPath="yes" />
What I am doing wrong?

The property defined via the property-Tag creates a public property in the MSI-Package which is a Windows Installer concept.
You are refering to this variable in the Source-Attribute of the File-Tag but that isn't the way you can use this property. You can only use them at runtime (e.g. to use them in Registry-Keys you create during the installation) but the Source-Attribut is resolved via compile-time of the package.
The Source-attribut of the File-Tag requires a path to variable that points to a location on the developer machine.
I assume you are looking for Wix precompiler directives:
<?define MyProperty = "C:\myfile.xml" ?>
<File Id="MyFileId" Name="myfile.xml" Source="$(var.MyProperty)" KeyPath="yes" />

Related

WiX Toolset: ICE03 Invalid identifier with RemoveFolderEx

I'm trying to create a .msi installer for a Node.js project using the WiX Toolset. I want to remove the node_modules folder during uninstall. This is the relevant excerpt from my .wxs file:
<Property Id='APPLICATIONFOLDER'>
<RegistrySearch Id='ApplicationFolder' Root='HKLM' Key='Software\[ProductName]' Name='InstallDir' Type='raw'/>
</Property>
<DirectoryRef Id='TARGETDIR'>
<Component Id='RemoveFolder' Guid='3e2231d9-61b3-41a2-b407-8df015be537e'>
<util:RemoveFolderEx Property='[APPLICATIONFOLDER]\node_modules' On='uninstall'/>
<RegistryValue Root='HKLM' Key='Software\[ProductName]' Name='InstallDir' Type='string' Value='INSTALLDIR' KeyPath='yes'/>
</Component>
</DirectoryRef>
I thought this would read the value from the registry, assign it to the property APPLICATIONFOLDER, and then in the RemoveFolderEx tag append the string \node_modules to that property's value.
But when I try to run this through light.exe, I get ICE03: Invalid identifier; Table: WixRemoveFolderEx, Column: Property, Key(s): wrf1A1445CB13E8BF98989EA24E3514470A.
Clearly, it is unhappy with my Property attribute, but what do I need to fix it? I've seen plenty of guides using this general pattern, but they always read the install dir value from the registry and then nuke that entire folder. That seems a little crass - if the user has added files to the directory I don't want to delete them. How can I specify a subfolder to delete?
I've solved the problem. Because I personally had a hard time figuring it out - the guides I've seen on RemoveFolderEx only all cover the same use case of nuking a folder saved to the registry, not a subfolder; and I find the WiX documentation to be less than beginner-friendly in most cases -, I am recording the solution here in case someone else should ever stumble upon the same problem.
As was pointed out already, Property does not work in the way I presumed in my question - it really does just accept the id of a property holding the path to the directory to delete. So you will definitely need to set a property in some way. (Some guides on the internet do not make this very clear.)
The next obvious path to investigate would be to assign the property a modified result of the registry search. However, this is impossible with WiX (to the best of my knowledge).
The answer lies in SetProperty. This, finally, allows to set a new property based on the one read from the registry.
It is worth noting that doing this still prevents the installation folder from being deleted, even if it empty. This, however, can easily be remedied by adding a RemoveFolder (without the Ex). This will delete the folder, but only if it is empty.
The relevant code that got it working for me is below.
<!-- Read the InstallDir from the registry and assign it to property APPLICATIONFOLDER -->
<Property Id='APPLICATIONFOLDER'>
<RegistrySearch
Id='ApplicationFolder'
Root='HKLM'
Key='Software\[ProductName]'
Name='InstallDir'
Type='directory'
Win64='yes'/>
</Property>
<!-- Set new property NODE_MODULES_FOLDER by appending node_modules\ to APPLICATIONFOLDER -->
<SetProperty
Id='NODE_MODULES_FOLDER'
Value='[APPLICATIONFOLDER]node_modules\'
Before='CostInitialize'/>
<Component Id='RemoveFolders' Guid='...'>
<!-- Remove the node_modules subfolder, using the property we created above -->
<util:RemoveFolderEx Property='NODE_MODULES_FOLDER' On='uninstall'/>
<!-- Remove main installation directory now, but only if it is empty. -->
<!-- That's why we're using RemoveFolder instead of RemoveFolderEx here. -->
<RemoveFolder Id='RemoveMainFolder' Property='APPLICATIONFOLDER' On='uninstall'/>
<RegistryValue
Root='HKLM'
Key='Software\[ProductName]'
Name='InstallDir'
Type='string'
Value='[INSTALLDIR]'
KeyPath='yes'/>
</Component>
I thought this would read the value from the registry, assign it to the property APPLICATIONFOLDER, and then in the RemoveFolderEx tag append the string \node_modules to that property's value.
It won't. As the doc says, Property is:
The id of a property that resolves to the full path of the source directory.
The easiest way to make that happen is to write the exact path you want to nuke to the registry.

How to set value of environment value based on install dir

In a Wix installer xml file, when creating an environment variable, how can I set the value of the env var based on the install directory that the user selected?
Currently, I have something like this, and the part I'm missing is ???:
<Component Id='CompId' Guid='xxx'>
<File Id='ProgramEXE' Name='foo.exe' DiskId='1' Source='foo.exe' KeyPath='yes' />
<Environment Id='FooInstall' Action='set' Name='FOO_INSTALL' Value='???'/>
</Component>
The Environment table's Value column is of type Formatted. Directory table entries become properties during CostFinalize so therefore you can just say [DIRECTORYNAME] such as [INSTALLLOCATION].

Migrating from WiX 3.10 to WiX 4.0: unhandled extension element

I'm migrating from WiX Toolset 3.10 to 4.0-pre. Updating namespaces went ok, but I'm still getting some errors in my NAnt build log.
I have Installer.wxs file:
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<Product ...>
<DirectoryRef Id="FolderCommon">
...
<Component Id="Registration_Component_12" Guid="..." KeyPath="yes">
<?include VS2012Package.wxi.bak?>
...
</Component>
...
</DirectoryRef>
...
</Product>
Where VS2012Package.wxi.bak file is generated via RegPkg.exe:
<Include>
<Registry Root="HKLM" Key="SOFTWARE\Microsoft\VisualStudio\11.0\InstalledProducts\VsPackage">
<Registry Name="Package" Value="..." Type="string" />
<Registry Name="UseInterface" Value="1" Type="integer" />
</Registry>
...
And my build fails with errors like this:
[exec] ...\Installer\VS2012Package.wxi.bak(3) : error CNDL0200 : The Component element contains an unhandled extension element 'Registry'. Please ensure that the extension for elements in the '' namespace has been provided.
I tried to add namespace 'http://wixtoolset.org/schemas/v4/wxs' to "<Include>" tag in VS2012Package.wxi.bak using external script before building, but errors just changed to error CNDL0005 : The Component element contains an unexpected child element 'Registry'
Thanks for any help!
The Registry element was deprecated in WiX v3.x and is obsoleted in WiX v4.x. Use RegistryValue instead.

WIX one or more Conditional Component with predefined Variables

Hi based on Environments(UAT,TEST,DEV,PROD) and Server Specific(Server1,Server2..) I am filtering the config files.
<Component Id="cmp39F4D3AA1248B5FE5EB2F92D189B27E1" Directory="dirCFCE6D07D3330FE628276777F0488B18" Guid="{56788F77-A729-47CE-BBA4-9D7D7F175536}">
<File Id="fil10B3B7732D0DDBD4AA773E0B7F34D092" KeyPath="yes" Source="$(var.SDirect.B2CWeb.ProjectDir)Web.ProdBuild.Web1.config.xml" >
<CopyFile Id="SCopy_ConfigPROD1" DestinationProperty="DestFilesWebsiteFolder" DestinationName="Web.config" />
</File>
<Condition> <![CDATA[ENVPROPERTY~="PROD"]]></Condition>
</Component>
The Above component works fine; the ENVPROPERTY Property value is set through command line when Installing by MSIEXEC.
But When I change the above statement as below doesn't work where the Installer need to detect the computername or Servername where it gets installed and based on that the installer must make sure to deploy the above component or not.
<Component Id="cmp39F4D3AA1248B5FE5EB2F92D189B27E1" Directory="dirCFCE6D07D3330FE628276777F0488B18" Guid="{56788F77-A729-47CE-BBA4-9D7D7F175536}">
<File Id="fil10B3B7732D0DDBD4AA773E0B7F34D092" KeyPath="yes" Source="$(var.SDirect.B2CWeb.ProjectDir)Web.ProdBuild.Web1.config.xml" >
<CopyFile Id="SCopy_ConfigPROD1" DestinationProperty="DestFilesWebsiteFolder" DestinationName="Web.config" />
</File>
<Condition> <![CDATA[ENVPROPERTY~="PROD" AND ComputerName~="Server1"]]></Condition>
</Component>
Can any one help in setting the conditional statement which satisfies ENVPROPERTY="PROD" and ComputerName="Server1" ie the servername(Machine) the MSI package gets installed. So that above components gets deployed and not skipped when package gets deployed.
Thanks in advance
Public Properties only can be used in command line. All letters should be in upper case for public properties. Use ComputerName property as COMPUTERNAME like the other one.

Add a new CLSID to windows registry using WiX

I am trying to register a new filter with Windows Desktop Search. Ideal way to achieve do this would be registering new filter with existing persistent handler CLSID. But this cannot be done since .html PersistentHandler CLSID, {eec97550-47a9-11cf-b952-00aa0051fe20}, is protected under WRP (More about the problem).
As a workaround, I am trying to create a different CLSID that does the same job as {eec97550-47a9-11cf-b952-00aa0051fe20}.
This is the sample code I am following. I am quite new to WiX and editing Windows registry.
<File Id="HTMLfilter.DLL">
<Class Id="$(var.CLSID_HtmlIFilter)" Context="InprocServer32" ThreadingModel="both" Description="Html Filter" />
</File>
Could someone help me regarding these;
How to create a CLSID that is not affiliated to any file? Since my
new CLSID is doing the work of above mentioned CLSID, I think this is
how it should be.
How to create a a sub-directory named PersistentAddinsRegistered
instead of InprocSever32
Thanks
Have a look at this page here shows how to add COM objects to installers
I suggest export selected branch to registry file (Export all or part of the registry to a text file).
Then using Heat.exe harvest registry file and include its output in your project.
This is an example
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Component Id="cmp6E2CE62C9ADECD355465514E3C8F354E" Guid="PUT-GUID-HERE" KeyPath="yes">
<RegistryKey Key=".ascx\PersistentHandler" Root="HKCR">
<RegistryValue Value="{eec97550-47a9-11cf-b952-00aa0051fe20}" Type="string" />
</RegistryKey>
</Component>
</DirectoryRef>
</Fragment>