Wix将组件复制到自定义操作中的多个文件夹

时间:2015-07-06 20:53:36

标签: c# wix

如何将安装项目中的一个文件复制到目标机器中的多个文件夹?

然而我想到了这样:

public class CustomActions
{
    [CustomAction]
    public static ActionResult CustomAction1(Session session)
    {
        session.Log("Begin CustomAction1");
        Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser;
        string keyname = "SOFTWARE\\SomeApp\\ExtPaths";
        String keyValue = hkcu.GetValue("Path templates").ToString();

        List<String> paths = ParsePaths(keyValue);
        foreach (var path in paths)
        {
            File.Copy(/*maybe component?*/);
        }
        return ActionResult.Success;
    }

    private static List<string> ParsePaths(string keyValue)
    {
        return keyValue.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();

    }

我不想在programm文件夹中安装组件,我需要将我的文件放入我之前找到的路径中。我应该在自定义操作中执行此操作吗?或者我应该采取不同的方式吗?

1 个答案:

答案 0 :(得分:1)

为此创建自定义操作是不必要的,这意味着您还必须手动删除文件(因为MSI不会意识到这些)。

从内存中你应该为每个文件创建一个Component(或者为所有文件创建一个<DirectoryRef Id="D.WEBSITE_INSTALL"> <Component Id="myComponentId" Guid="8853AEFC-CF85-4D20-89D2-CCB59593B973"> <File Id="someFileId" KeyPath="yes" Source="SomePath\SomeFile.ext" /> </Component> </DirectoryRef> ,但如果你打算修补或合并,那么单独执行它们会更好。

E.g。

<ComponentGroup Id="SomeGroupId">
      <ComponentRef Id="myComponentId"/>
</ComponentGroup>

然后您应该能够在另一个Directory / ComponentGroup / Feature中引用它。 E.g。

url_handlers

这应该是一般性的想法,道歉这是基于我的一个安装人员而我还没有对此进行测试。