简体   繁体   English

wix#用于创建安装程序的脚本

[英]wix # script for creating a installer

I have a wpf application which helps user to selects the directory path and when he click create installer button then I want to create installer for user selected directory(inside directory there may me more than one file). 我有一个wpf应用程序,它可以帮助用户选择目录路径,当他单击“创建安装程序”按钮时,我想为用户选择的目录创建安装程序(目录中可能有多个文件)。

I came to know that I can use a wix# script and then I call this script when button is clicked. 我知道我可以使用wix#脚本,然后在单击按钮时调用此脚本。 But I don't know how to write a wix# script which take input for file (the file for that installer is going to create). 但是我不知道如何编写一个wix#脚本来接受文件输入(该安装程序的文件将要创建)。

I am familier with basic wix and new to wix #. 我熟悉基本的wix和新的wix#。 Please help me to solve my problem. 请帮助我解决我的问题。

You could try the Wixsharp solution. 您可以尝试Wixsharp解决方案。

You can get it from the nuget reference option (Visual studio), then you just need to write the code so it works like you want it. 您可以从nuget引用选项(Visual Studio)中获得它,然后只需编写代码即可使其按需运行。

I'll make a C# example: 我将举一个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;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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