When can I get the target directories in a WIX installer? - wix

So I have a custom action
<CustomAction Id="GetTarget"
BinaryKey="CA"
DllEntry="GetTargetPath"
Execute="immediate"
Return="check"
HideTarget="no"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="GetTarget" After="CostFinalize">(NOT REMOVE = "ALL")</Custom>
</InstallExecuteSequence>
This is calling a DLL that calls the method session.GetTargetPath("TARGETPATH"); But I get an exception "The directory name is invalid. TARGETPATH". I have the custom action as After="CostFinalize" as this is what I read from a source (which I can provide) but I think there is a mistake and I think that I just have to to execute the action at the right time.

I think you meant TARGETDIR. Take a look at http://msdn.microsoft.com/en-us/library/windows/desktop/aa371685(v=vs.85).aspx

Related

Wix - Running a deferred action after InstallFinalize

Reading the Wix help I see that "Deferred execution custom actions must come after InstallInitialize and come before InstallFinalize in the action sequence."
However I have to perform a database upgrade on a remote box which needs to be run with the user credentials so I have created an immediate action and set it to run after installFinalize. Subsequently, I need to run another custom action to start a windows service which reads values from the database, this requires elevated (system) permissions, so needs to be a deferred custom action. Which as the Wix help kindly explains to me that I cannot do.
Any help, tips or Wix tricks appreciated please
<CustomAction Id="LaunchServerUpgrade" FileKey="Config.exe" ExeCommand="/upgradeServer"
Return="ignore" Execute="deferred" Impersonate="no"/>
<CustomAction Id="LaunchServerDatabaseUpgrade" FileKey="Config.exe" ExeCommand=" /databaseupgrade"
Return="ignore" Execute="immediate"/>
<CustomAction Id="LaunchServerStartServices" FileKey="Config.exe" ExeCommand=" /startservices"
Return="ignore" Execute="deferred" Impersonate="no"/>
<InstallExecuteSequence>
<Custom Action="LaunchServerUpgrade" Before='InstallFinalize'>
<![CDATA[(SERVERCONFIGUPGRADE) AND NOT REMOVE)]]>
</Custom>
<Custom Action="LaunchServerDatabaseUpgrade" After='InstallFinalize'>
<![CDATA[(SERVERCONFIGUPGRADE) AND NOT REMOVE)]]>
</Custom>
<Custom Action="LaunchServerStartServices" After='InstallFiles'>
<![CDATA[(SERVERCONFIGUPGRADE) AND NOT REMOVE)]]>
</Custom>
</InstallExecuteSequence>

Triggering custom action in a silence mode

I'm working on a setup that validate many user inputs by a custom action. The event "DoAction" of publish control are doing very good job, but I figured out that no one custom validation are triggered if I execute the setup in silence mode.
I tried InstallExecuteSequence like the Yen Tran's blog (http://yentran.org/blog/2013/09/27/wix-executing-custom-action-before-starting-windows-service/) but still not working.
<Frament>
<Binary Id="CALibrary" SourceFile="$(var.Project.Installer.CustomAction.TargetDir)CustomAction.CA.dll" />
<CustomAction Id ="ProxyCheck" BinaryKey="CALibrary" DllEntry="Proxy" Execute="immediate" Return="check" />
<CustomAction Id ="ActivationCheck" BinaryKey="CALibrary" DllEntry="Activation" Execute="immediate" Return="check" />
</Frament>
...
<Fragment>
<InstallExecuteSequence>
<Custom Action="ActivationCheck" Before="InstallInitialize" Overridable="yes">PROXYSERVER</Custom>
</InstallExecuteSequence>
With Orca.exe I found that the action was not configured in InstallExecuteSequence no matter what I do. Reviewing all the files for the thousandth time, I found that I was putting the instruction of InstallExecuteSequence in a wrong place, moved into the <Product> </Product> and then everything works well.

WiX. Rollback custom action when is canceled installation

I have a custom action
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
My custom action does backup and resolved database. I need to do rollback (drop database) when is canceled installation.
I did:
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<CustomAction Id="myActionRollbackId" BinaryKey="myActionRollback" DllEntry="MySimpleAction" Execute="rollback" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
<Custom Action="myActionRollbackId" Before="myActionId">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
But I was having an error.
If I do like this:
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<CustomAction Id="myActionRollbackId" BinaryKey="myActionRollback" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
<Custom Action="myActionRollbackId" After="myActionId">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
My custom action myActionRollbackId works.
How to run rolback when is canceled installation?
Someone can help me?
The custom action which runs on install and does something with the database should be deferred (Execute='deferred'). Its corresponding rollback action should be Execute='rollback'. When you schedule these custom actions, the rollback action should go first.
Also, make sure the conditions are set properly.
Installation is always done in transaction. when you launch an installer, it first creates something called installation script which is like a to do list of what it will do while installation.
When we set some custom action as Execute="immediate", it gets executed immediately but when we set our action as Execute="deferred", it gets added in the installation script, hence rollback becomes easy for this.
Now one thing to note here is that we get access to session in Execute="immediate" mode, but we cannot access session in Execute="deferred" mode.
If we try to access session it will give error, which in this case might be the reason for your error...

How can I include a strong name assembly file in my installer

I have a custom action to execute a custom action DLL but it is failing and I believe it's because it does not know how to read the strong name assembly
so I have this:
<Binary Id="StrongName" SourceFile="$(var.MyProject.TargetDir)MyProject.CA.dll"/>
<CustomAction Id="CreateIt"
BinaryKey="StrongName"
DllEntry="Create"
Execute="deferred"
Return="check"
HideTarget="no"
Impersonate="no" />
<CustomAction Id="RemoveIt"
BinaryKey="StrongName"
DllEntry="Remove"
Execute="deferred"
Return="check"
HideTarget="no"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="CreateIt" Before="InstallFinalize">(NOT REMOVE = "ALL")</Custom>
<Custom Action="RemoveIt" Before='InstallFinalize'>(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
So how do I reference the signature as I execute this DLL?
I assume from the *.CA.DLL nomenclature that you are using that this is a DTF custom action. This is a native encapsulated DLL that hosts your managed DLL. Being native, it can't be strong named.
Log the install and look through the log for the reason it is failing.
The solution to my problem was a security issue caused by an obsolete library which is not supported in .NET 4 and it is a different topic so I will not go into detail on it unless someone is curious.

Sequencing a custom action in WiX before "LaunchConditions"

Is it possible to sequence a custom action before "LaunchConditions"?
This is my custom action:
<CustomAction
Id="CA_vcAppRunning"
BinaryKey="vcShowMsg"
DllEntry="IsAppRunning"
Return="check"
Execute="immediate"/>
Sequenced in <InstallExecuteSequence/>
<Custom Action="CA_vcAppRunning" Before="LaunchConditions" />
I tried this, opened the MSI file in Orca and found that my custom action is sequenced at "99".
But when I tried to install, it never got called.
I want to schedule this before LaunchConditions as this custom action is supposed to set a property which is used in the LaunchCondition (if the application is running, exit the installer/updater).
Don't schedule it in before LaunchConditions, schedule it after FindRelatedProducts and then add a second custom action that blocks install based on the results from your first CA.
This is the same method used to prevent downgrading in many tutorials, e.g.
<CustomAction Id="CA_BlockOlderVersionInstall" Error="!(loc.LaunchCondition_LaterVersion)" />
<InstallExecuteSequence>
<LaunchConditions After="AppSearch" />
<Custom Action="CA_BlockOlderVersionInstall" After="FindRelatedProducts">
<![CDATA[NEWERVERSIONDETECTED]]>
</Custom>
</InstallExecuteSequence>
<InstallUISequence>
<LaunchConditions After="AppSearch" />
<Custom Action="CA_BlockOlderVersionInstall" After="FindRelatedProducts">
<![CDATA[NEWERVERSIONDETECTED]]>
</Custom>
</InstallUISequence>