[wix-users] Custom Action to Create and Install a File?

Russell Haley russ.haley at gmail.com
Sun Feb 16 20:44:45 PST 2020

Thank you for the response, I didn't see this come through!l That's an
interesting post from 13 years ago.

I started drilling into the MSI database information here:

>From what I can tell I need my custom action to run after the feature
selection and then create my file. If my desired feature is selected, then
I need to insert into Component, FeatureComponent and File. I started going
down the SQL route. Here is a test custom action that is supposed to create
a new config file and add it to "Feature2" (NOTE: This code doesn't work
yet...or at all?).

public class CustomActions
        public static ActionResult CustomAction1(Session session)
            session.Log("Begin CustomAction1");
                session.Log("TESTING: Found Feature2");
                File.WriteAllText(@"C:\temp\mytemp1.txt", "This is a test
of the public broadcast system.");
                var db = session.Database;

                Guid id = Guid.NewGuid();
                session.Log("TESTING: id = " + id);
//Used a string builder just because I thought the queries would get long
                StringBuilder sb = new StringBuilder();
                sb.Append("INSERT INTO `Component` (`ComponentId`,
`Directory_`) VALUES(?, ?)");
                session.Log("TESTING: " + sb.ToString());
                db.Execute(sb.ToString(), id, "feature2folder2");

                sb.Append("INSERT INTO `FeatureComponent` (`Feature_`,
`Component_`) VALUES(?, ?)");
                session.Log("TESTING: FeatureComponent " + sb.ToString());
                db.Execute(sb.ToString(), "Feature2", id);

                db.Execute("INSERT INTO `File` (`Component_`, `FileName`,
`FileSize`) VALUES (?, ?, ?)",
                    id, "config-5.3.lua", 1024);
                session.Log("TESTING: File");
            return ActionResult.Success;

However, what I don't know is how to point to the source file in the
database? Do I need to put it in the database as a blob or a varchar or
something? Or can I just add a reference from the local temp directory?

Thanks again!

On Thu, Feb 6, 2020 at 5:34 PM Blair Murri via wix-users <
wix-users at lists.wixtoolset.org> wrote:

> In a word: yes, for both questions. Look for Bob's blog entry about
> "semi-custom" actions.
> Blair
> Get Outlook for Android<https://aka.ms/ghei36>
> ________________________________
> From: wix-users <wix-users-bounces at lists.wixtoolset.org> on behalf of
> Russell Haley via wix-users <wix-users at lists.wixtoolset.org>
> Sent: Sunday, February 2, 2020 11:42:46 AM
> To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
> Cc: Russell Haley <russ.haley at gmail.com>
> Subject: [wix-users] Custom Action to Create and Install a File?
> Hi,
> I'm pretty chuffed. I have a new installer for my WinLua distribution that
> now includes the Lua package manager called LuaRocks and a custom compiler
> toolchain using llvm-mingw. My current installer has a CustomAction that
> creates a config file for the package manager named for the appropriate
> version of Lua. The current version of Lua is 5.3.5, so the config file
> needs to be named Config-5.3.lua. I currently save this file under the
> install directory of <program files>\WinLua\LuaRocks.  This custom action
> runs POST installation so I have the paths I need for creating the contents
> of the file. I do not want this file in a user accessible directory.
> My questions:
> 1) Can I use a custom action to create the file before the installation
> completes and ADD the config file to the list of files to be removed (I
> think that's termed the installer database)?
> 2) What about things like environment variables? Can I create them based on
> installer information prior to the completion of the install process and
> have the installer remove them? Specifically I want to create an
> environment variable called LUAROCKS_SYSCONFDIR and store the path of the
> config-5.3.lua mentioned above. However, the name and path won't be known
> until AFTER the file is created? I can already add to the PATH variable
> based on the installer paths, but this feels different.
> All my source code can be found here:
> https://github.com/WinLua/WinLua-Source-Code/tree/master/WinLua-Release3/WinLua-Installer
> Regards,
> Russell
> ____________________________________________________________________
> WiX Toolset Users Mailing List provided by FireGiant
> http://www.firegiant.com/
> ____________________________________________________________________
> WiX Toolset Users Mailing List provided by FireGiant
> http://www.firegiant.com/

More information about the wix-users mailing list