how to get wix propery value to wix vb custom action project? - vb.net

I am struggeling with this &%^&##$ problem for over two weeks and it is still not working. I need the user to input some data and that data needs to be sent to my WIX VB custom action project. however it does never reach it. I currently have the following code in WIX:
Input of the user:
<Control Id="InputField" Type="Edit" X="20" Y="100" Width="140" Height="18" Property="ValueAdaptionScript" Text="{40}"/>
Adding the DLL to the installer:
<ComponentGroup Id ="DLL" Directory ="INSTALLFOLDER">
<Component Id ="StringTransfer" Guid ="{479947FA-C324-411C-9B98-083E79C116CB}">
<File Id ="StringTransfer" KeyPath="yes" Source="C:\Users\fjansen\Documents\Visual Studio 2015\Projects\String Transfer\Data Transfer\obj\x86\Debug\DataTransfer.CA.dll" />
</Component>
</ComponentGroup>
The custom actions and the Binary to point towards the DLL:
<Binary Id="StringTransfer" SourceFile="C:\Users\fjansen\Documents\Visual Studio 2015\Projects\String Transfer\Data Transfer\obj\x86\Debug\DataTransfer.CA.dll" />
<CustomAction
Id="SetProperties"
Property="ValueAdaptionScript"
HideTarget="no"
Value="[MachineIdNumber]"
/>
<CustomAction
Id="ValueAdaptionScript"
BinaryKey="StringTransfer"
DllEntry="CustomAction1"
Execute="deferred"
Impersonate="no"
Return="check"
/>
<InstallExecuteSequence>
<Custom Action="SetProperties" Before="ValueAdaptionScript" />
<Custom Action="ValueAdaptionScript" Before="InstallFinalize">NOT REMOVE="ALL"</Custom>
</InstallExecuteSequence>
in the WIX custom action project I have made a function to write to a file so I can see what is being recieved from WIX. this is just to test the passing of values, if passing of the values work I adapt the code the let it replace a specific piece of text with the input from the user in a .INI file.
the code of the WIX custom action project:
Imports System.IO
Imports System.Reflection
Public Class CustomActions
Public Shared Property MachineIdNumber As String
Public Shared Property ValueAdaptionScript As String
<CustomAction()>
Public Shared Function CustomAction1(ByVal session As Session) As ActionResult
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True)
file.WriteLine("test")
file.WriteLine(MachineIdNumber)
file.WriteLine(ValueAdaptionScript)
file.WriteLine(CustomAction1)
file.Close()
Return ActionResult.Success
End Function
End Class
when the installer is ran with all this code I do get a text file with the following content: text and 0. the first is logical since i hard coded it and the 0 is the product of CustomAction1 and means that the CustomAction has ended succesfull. that is all good and well, bud I don't get the value I would like to see.
I really need help with this, since I just don't get it working and have spent a huge amount of time on this problem. bud mainly since this is the last obstacle before I am able to deploy the installer.
Thanks in advance,
F.J

There are a few things incorrect here.
Properties passsed between the UI sequence and the execute sequence need to be all uppercase - that means they are public. They also should be declared first with Secure='yes'.
You don't declare propErties in your custom action code, you get them from the installation process. If your CA was immediate you'd say something like varname = session["VALIDATIONSCRIPT"] but it's deferred, so this is a good overview:
http://vadmyst.blogspot.com/2006/05/deferred-custom-actions-with-wix.html
and having set up the deferred CA property you'd use varname = session["CustomActionData"]
and this too:
https://www.firegiant.com/wix/tutorial/events-and-actions/at-a-later-stage/

Related

WiX customaction doesnot have value for session.Property["CustomActionData"]

I have to pass a value to my custom action in patch release for my feature. I did some research and did the following:
<CustomAction Id="CustomAction1" Property="customaction2" Value="Value1" />
<CustomAction Id="customaction2" BinaryKey="Binary.dll"
DllEntry="Functionname" Impersonate="no"
Execute="immediate" Return="check" />
I also updated the installExecuteSequence as below:
<Custom Action='CustomAction1' After="InstallFinalize"><![CDATA[PATCH]]></Custom>
<Custom Action='customaction2' After="CustomAction1"><![CDATA[PATCH]]></Custom>
I also added the componentrefs to the patch.wxs file.
<CustomActionRef Id="CustomAction1.PackageGuid"/>
<CustomActionRef Id="customaction2.PackageGuid"/>
To access this parameter value, I tried the following code in my customaction "Functionname" :
var value = session.Property["CustomActionData"];
The "value" is Empty. I did some debugging and found that, i am getting the value from below code:
var value = session.Property["customaction2.PackageGuid"];
I have not seen any examples that access properties with packageGuids also. I am not sure why the first approach(using "CustomActionData") is not working for me.
Can you guys let me know what i am missing?
Also, Is there any harm in using with packageGuids? If not, i am planning to continue this way. Please let me know if you need me to try any other st

Set File Name to Property

I have a Merge Module which installs a file. I would like to use a property passed to the Merge Module during MSI creation. Something like:
<Configuration Name='FileNameProperty'
Format='Text'
DefaultValue='[FileNameProperty]' />
<Substitution Table='CustomAction'
Row='SetFileName'
Column='Target'
Value='[=FileNameProperty]' />
<CustomAction Id='SetFileName'
Property='MYFILENAME'
Value='[MYFILENAME]' />
<InstallExecuteSequence>
<Custom Action='SetFileName'
Before='LaunchConditions'>1</Custom>
</InstallExecuteSequence>
...
<File Name="[MYFILENAME]"
Source="my-file.exe" />
Currently I am using a Custom Action, namely Type 51, which works when substituting property values for other element attributes, such as ServiceInstall DisplayName. However, in this instance the file is deployed as [MYFILENAME].
I've looked through the other Custom Actions provided by MSDN, but can't find anything that fits this situation. Any suggestions or idea if this is even possible?
My last ditch option is to include File elements for each variation of file name and select the desired file based off condition, but I would like to avoid that.
File names aren't formatted so properties can't be used. If you use multiple files, WiX's smart cabbing ensures the copies don't take up extra space in your cabinet.

Set the Property value to an ini file WIX

I was setting a property value inside a Dialog using Edit Control. But when i used the same property for writing inside an ini value it is not writing the updated value and writing only old value. My WIX source code is given below(writing only important codes as my wix code is too large)
<Property Id="testNumber" Value="1122" />
<CustomAction Id="SettestNumber" Property="ModifiedtestNumber" Value="[testNumber]" />
<ComponentGroup Id="INIFileGroup">
<Component Id="IniFile" Guid="{0ded271b-9268-49e7-8c13-60c7538acc25}" KeyPath="yes" Directory="DirCfg" >
<IniFile Id="IniPath" Action="addLine" Directory="Dirtest" Key="testkey" Name="test.ini" Section="test" Value="[ModifiedtestNumber]" />
</Component>
</ComponentGroup>
<InstallUISequence>
<Custom Action="SettestNumber" Sequence="1299"/>
</InstallUISequence>
<Dialog Id="testNumberUI" X="50" Y="50" Width="375" Height="270" Title="[ProductName]" CustomPalette="yes">
<Control Type="Edit" Id="test_Number" Width="50" Height="15" X="258" Y="53" Property="testNumber" Text="{50}" TabSkip="yes"/>
</Dialog>
I am giving the value 1212 in the Control edit box and installing but inside the test.ini file it is not getting updated and value is 1122. Could someone please provide a way for me to update the Modifedtestnumber to the ini file
Note:
When i put the Custom action inside < InstallExecuteSequence/> the value inside the ini file was null
Your property need to be public (all caps TESTNUMBER) and marked with Secure attribute so that it's listed in the SecureCustomPublicProperties property. Also be aware that properties are not persisted. You need to use something like the WiX remember property pattern for the value to be loaded from the INI file during subsequent transactions such as repairs and upgrades.

WiX: Does setting MultiInstance attribute to yes generate unique component IDs for each instance transform, even when static guids are used?

I have two msi packages that gets triggered by a bootstrapper and together install a product. I have multiple instance transforms defined for each msi, and I want to set the MultiInstance attribute to 'yes' for all the components in the harvested fragment such that a new component GUID will be generated per instance transform. (It seems that for now, there isn't a heat parameter that you can set to do this, and it has to be accomplished via an xslt transformation.)
I'd want to use -gg flag for Heat to auto-generate static GUIDs because the install directory is set during run-time as a parameter and is not necessarily a standard directory.
Basically, the output should look like:
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Component Id="cmp32EAD7F5A154CBFA668F294AEEE77B45" Guid="{6529235A-EE06-47EB-A56B-1D016B2396CF}" MultiInstance="yes" >
<File Id="fil3F2F6C0F947339E1ED2CF4459569CC5A" KeyPath="yes" Source="$(var.BIN)\File1.txt" />
</Component>
</DirectoryRef>
... Etc.
I'm wondering, even if the GUID is hard-coded such that the linker does not generate it (like above, instead of Guid="*"), will the MultiInstance attribute being set to 'yes' generate unique guids for each instance transforms' components? I sot of became confused about this when I was test calling the MsiGetProductCode by passing in a component guid for a file, which was defined like below:
<Component Id="ProductComponent" Guid="{1C149757-1E1D-424D-AF77-A156CB87F0BF}" MultiInstance="yes">
<!-- TODO: Insert files, registry keys, and other resources here. -->
<File Id="Picture1" Source="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg" ProcessorArchitecture="x64" />
</Component>
* This is a test file that gets installed for all instance transforms defined.
I had two instances from the msi installed (Instance1, Instance2) and the MsiGetProductCode function ran as a part of a custom action that executes during uninstall. On the first execution of MsiGetProductCode, I got the ProductCode of Instance1. On the second execution of MsiGetProductCode (after Instance1 was removed), I got the ProductCode of Instance2. It seemed like that static component id had been used for both instance transforms.
Is the unique component ID generated by the MultiInstance attribute being set to 'yes' not supposed to replace that visible component guid? I haven't had any issues certain files or registry values not being removed due to a component still being used. Basically, I want to confirm that unique guids are being generated per instance and that it's safe to use the MultiInstance attribute to guarantee that component ID collisions will not occur, even when static guids are in use. Could someone kindly elaborate how this works in the background?
Thanks a lot in advance!
It's pretty easy to confirm WiX behavior just by logging the install. Consider the following code:
<Component Id="test" Guid="{EAF11690-2396-4EBE-A74D-37FA1751BBC3}" MultiInstance="yes">
<File Id="test" Source="C:\windows\notepad.exe" KeyPath="yes" />
</Component>
<InstanceTransforms Property="INSTANCEID">
<Instance Id="I01" ProductCode="{7474D99A-B56C-4767-B437-52F56746274A}" ProductName="ProductName2-1" UpgradeCode="{7C2BE622-7543-4F22-A0ED-A9FD28C78C8A}"/>
</InstanceTransforms>
Logging the base and secondary installation reveals that the GUID is unique / transformed.
Another thought would be to extract the instance transform from the MSI and apply it using ORCA to see the differences.
MSI (s) (E4:A4) [10:36:37:021]: Executing op:
ComponentRegister(ComponentId={EAF11690-2396-4EBE-A74D-37FA1751BBC3},KeyPath=C:\Program
Files
(x86)\MyCompany\ProductName2\notepad.exe,State=3,,Disk=1,SharedDllRefCount=0,BinaryType=0)
MSI (s) (E4:DC) [10:37:04:234]: Executing op:
ComponentRegister(ComponentId={BEC4E6A5-9CFB-5C77-A854-CC0179CFEDCE},KeyPath=C:\Program
Files (x86)\My
Company\ProductName2\notepad.exe,State=3,,Disk=1,SharedDllRefCount=0,BinaryType=0)

How can I have a WiX Property default to null?

I am working on a set of WiX installers that are going to share a common form. Every application needs the values set, but they are going to be different for each application.
I am trying to allow for the properties (which are linked to controls) to have a default value (or not) and to allow for the property values to be set via command line.
in my "SharedDialog.wxs" I have:
<Fragment>
<PropertyRef Id="PROP1"/>
<PropertyRef Id="PROP2"/>
<UI>
<Dialog Id="SharedDialog" Width="370" Height="270" Title="[ProductName]">
<Control Type="Edit" Id="1" Property="PROP1" Wid... Indirect="no" />
<Control Type="CheckBox" Id="2" Property="PROP2" Wid...
CheckBoxValue="1" Indirect="no"/>
</Dialog>
</Fragment>
In a file for the application specific project:
<Fragment>
<Property Id="PROP1" Value="Test"/>
<Property Id="PROP2" Value="1"/>
</Fragment>
This all works for what I am trying to do, but the problem is that when I want to clear the values as so: (so they don't have a default)
<Fragment>
<Property Id="PROP1"/>
<Property Id="PROP2"/>
</Fragment>
I get this error:
Unresolved reference to symbol 'Property:PROP1' in section 'Fragment:'.
Unresolved reference to symbol 'Property:PROP2' in section 'Fragment:'.
WiX also will not let you set value to "". The problem is that as far I can tell the checkbox will always be checked if the property has a value. How can I set the property "PROP2" to "null"?
You can undefine an existing property by setting it equal to an empty string wrapped in braces like this: PROPERTY = {} in a set property custom action. This means the property doesn't exist, it is not an empty string. See the explanation here.
For properties to be available from the command line they must be PUBLIC - they are the properties that are all UPPERCASE.
Setting PUBLIC PROPERTIES secure means they can be passed from the client to the server installation process which is required for properties that are used in deferred mode custom actions. Technically this adds them to the list of SecureCustomProperties.
You can give PUBLIC PROPERTIES a default value in the Property table, and then set other values from the command line. The command line overrides the defaults:
msiexec.exe /I "C:\Test.msi" /QN /L*V "C:\log.log" TEST="MyValue" TEST2="MyValue"
See more info:
How to set a check box to "unchecked" from the msiexec command line?
Nevermind, I found the solution:
<Fragment>
<Property Id="PROP1" Secure="yes"/>
<Property Id="PROP2" Secure="yes"/>
</Fragment>