【问题标题】:wix # script for creating a installerwix # 创建安装程序的脚本
【发布时间】:2015-04-01 08:59:34
【问题描述】:

我有一个 wpf 应用程序,它可以帮助用户选择目录路径,当他单击创建安装程序按钮时,我想为用户选择的目录创建安装程序(目录内可能有多个文件)。

我知道我可以使用 wix# 脚本,然后在单击按钮时调用此脚本。但我不知道如何编写一个 wix# 脚本来输入文件(该安装程序的文件将被创建)。

我熟悉基本的 wix 和新的 wix #。请帮我解决我的问题。

【问题讨论】:

    标签: c# wpf wix wixsharp


    【解决方案1】:

    您可以尝试 Wixsharp 解决方案。

    您可以从 nuget 参考选项 (Visual Studio) 中获取它,然后您只需要编写代码,让它按您想要的方式工作。

    我将制作一个 C# 示例:

    static string sRootDir = @"<Path of Source directory>";
    static void BuildMSI()
            {                                  
                WixEntity[] weDir = new WixEntity[0];
                weDir = BuildDirInfo(sRootDir, weDir);
                var project = new Project("My product", weDir)
                {
                    GUID = Guid.NewGuid(),
                    //UI = WUI.WixUI_InstallDir,
                    Version = new Version(55, 0, 0, 0),
                    UpgradeCode = guidUpgradeCode, // Forwarded if upgrading existing product
                    MajorUpgradeStrategy = new MajorUpgradeStrategy
                    {
                        UpgradeVersions = VersionRange.OlderThanThis,
                        PreventDowngradingVersions = VersionRange.NewerThanThis,
                        NewerProductInstalledErrorMessage = "Newer version already installed"
                    }
                };
    
                project.BuildMsi(project);
            }
    
    
    
    static WixEntity[] BuildDirInfo(string sRootDir, WixEntity[] weDir)
            {
                DirectoryInfo RootDirInfo = new DirectoryInfo(sRootDir);
                if (RootDirInfo.Exists)
                {
                    DirectoryInfo[] DirInfo = RootDirInfo.GetDirectories();
                    List<string> lMainDirs = new List<string>();
                    foreach (DirectoryInfo DirInfoSub in DirInfo)
                        lMainDirs.Add(DirInfoSub.FullName);
                    int cnt = lMainDirs.Count;
                    weDir = new WixEntity[cnt + 1];
                    if (cnt == 0)
                        weDir[0] = new DirFiles(RootDirInfo.FullName + @"\*.*");
                    else
                    {
                        weDir[cnt] = new DirFiles(RootDirInfo.FullName + @"\*.*");
                        for (int i = 0; i < cnt; i++)
                        {
                            DirectoryInfo RootSubDirInfo = new DirectoryInfo(lMainDirs[i]);
                            if (!RootSubDirInfo.Exists)
                                continue;
                            WixEntity[] weSubDir = new WixEntity[0];
                            weSubDir = BuildDirInfo(RootSubDirInfo.FullName, weSubDir);
                            weDir[i] = new Dir(RootSubDirInfo.Name, weSubDir);
                        }
                    }
                }
                return weDir;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 2020-02-25
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多