Yes, that is the approach I went with to get it to work, and it worked 
beautifully, so as it turns out, I was basically just wondering why I couldn't 
access the installer properties in a deferred action.

Thanks for the answer, it helped a bit with my understanding of the beast 
called Windows Installer... 5% understanding down, 95% to go, or so it feels at 
times. 

/Thomas

-----Original Message-----
From: Blair [mailto:os...@live.com] 
Sent: 10. oktober 2009 23:30
To: 'General discussion for Windows Installer XML toolset.'
Subject: Re: [WiX-users] How to modify a file during install using a CA

All "in-script" actions (deferred, rollback, and commit) do not have access
to session properties or the database. You have to pass them information
using properties (named after the in-script action's name) that the action
can retrieve using the special "CustomActionData" property.

In your case I would recommend you instead create an immediate custom action
that takes the properties you need to encrypt and generate properties that
contain those encrypted values, and then you can use XmlConfig and/or
XmlFile to place the values of the properties you generate with the
encrypted values.

-----Original Message-----
From: Thomas Due [mailto:thomas....@scanvaegt.dk] 
Sent: Saturday, October 10, 2009 4:45 AM
To: wix-users@lists.sourceforge.net
Subject: [WiX-users] How to modify a file during install using a CA

During the install interview I collect information about the database
connection and this information has to be added to an xml file which is
added during install. I could do this using the XmlConfig or XmlFile
elements, but unfortunately some of the information have to be encrypted
before added to the file. This is, of course, not possible using the MSI or
WiX elements, so I have to use a CA which then handles the encryption. 

The Xml is used by a windows service installed and started during the
install, so I have to modify the file AFTER the files have been installed,
but before the service is started. 
I struggled with this for a while, it was easy enough to find the exact spot
to call the CA, however it seems (according to the log file) that the MSI
makes two passes, so to speak. 
And the CA fired during the first pass where the installer is simply
figuring out what to do, as far as I can figure. 

So, I figured out that I need to delay the execution of the CA to the second
pass, but how to do that? I have tried with Execute="commit" and
Execute="Deferred" like this: 

<CustomAction Id="AddXmlConfig" BinaryKey="XmlConfig" DllEntry="AddXml"
Execute="commit"/>
<InstallExecuteSequence>
    <RemoveExistingProducts After="InstallInitialize"/>
    <LaunchConditions After="AppSearch"/>
    <Custom Action="AddXmlConfig" After="InstallServices"
>SERVERINSTALL</Custom>
</InstallExecuteSequence>

But this results in this exception thrown:

System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. --->
Microsoft.Deployment.WindowsInstaller.InstallerException: Cannot access
session details from a non-immediate custom action

What does this mean? Why can I not access session details during commit or
deferred, and how do I access the properties then? 

My CA looks like this, somewhat shortened though: 
        
[CustomAction]
public static ActionResult AddXml(Session session)
{
  string xmlDoc = Path.Combine(session["INSTALLDIR"], "configuration.xml");
  // Exact data from Session properties and encrypt where necessary

  XmlDocument doc = new XmlDocument();

  if (File.Exists(xmlDoc))
  {
    doc.Load(xmlDoc);

    // Add nodes and attributes to the xml document
    
    doc.Save(xmlDoc);

    return ActionResult.Success;
  }
  else
    return ActionResult.NotExecuted;
}

So assuming that I am not completely off track, how do I accomplish this
task? 
To sum it up: 

I need to modify a xml file using a CA during installation, but before
starting services. I have a work-around that actually works, where I simply
perform the encryption in the CA and lets my installer handle the xml file
modifications. I would like to know why this is not working though, and how
I MAKE it work. Next time, it may not be possible to modify the file using
only msi and wix. 

Any ideas?

/Thomas

----------------------------------------------------------------------------
--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users




------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to