简体   繁体   中英

How to create a wix type 35 custom action

I have been searching for a solution to programmatically overwrite a directory path for an feature for my application.

I found out that I need a type-35 custom action ( https://msdn.microsoft.com/en-us/library/windows/desktop/aa368093(v=vs.85).aspx )

I searched the internet for a while but nowhere I can find how to create such custom action in C#.

My current custom action looks like:

<CustomAction Id="CheckForSynergyInstallation"
          Return="check"
          Execute="immediate"
          BinaryKey="Real.CustomActions"
          DllEntry="GetVersionInformation" Directory="SYNERGY_FEATURE_FOLDER" />

And the C# code for it like this:

 var synergyFolder = new FileInfo(exactSynergyVersionConfigurationFile).Directory.FullName;
                log.Info($"Synergy Folder set to {synergyFolder}");

                session["SYNERGY_FEATURE_FOLDER"] = synergyFolder;

The type 35 custom action calls MsiSetTargetPath to change the directory's location. If you already have a DTF-based custom action, you can call session.SetTargetPath instead of setting the property.

If you do not already have a code-based custom action, you can use the CustomAction element with slightly fewer parameters to yield a type 35 action. Namely omit BinaryKey and DllEntry:

<CustomAction Id=... Return=... Execute=...
    Directory="SYNERGY_FEATURE_FOLDER" Value="location"/>

Do you mean that just the files in that feature are going to a different location than the other files in the setup? What you are doing looks like it will cause the INSTALLFOLDER / TARGETDIR location to be set, which means all files destined for INSTALLFOLDER will go to that location. That doesn't seem to be what you're asking for when you say you want the files in a feature to go somewhere different.

If there are some files that you want to send to some folder that you set, and you want the rest to go their predefined locations (ProgramFiles, GAC, Common Files etc) then you basically just define a directory property, and specify your components under that directory. Your custom action will set that property name, so the directory location has the required value and the rest of the files go where they are supposed to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM