Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Wix构建MSI的递归dirfile#_C#_Wix_Windows Installer_Wixsharp - Fatal编程技术网

C# 使用Wix构建MSI的递归dirfile#

C# 使用Wix构建MSI的递归dirfile#,c#,wix,windows-installer,wixsharp,C#,Wix,Windows Installer,Wixsharp,我正在探索Wix的特性,与Wix相比,它的简单性让我大吃一惊。我们已经在使用QT安装程序框架,但我们的客户也需要MSI安装包 我已经有一个目录,其中包含我们产品的所有文件,只有一个包。我试图将C:\Temp\MyProductFiles中的所有文件都包含到我的MSI安装程序中 using System; using WixSharp; class Script { static public void Main(string[] args) { Compiler

我正在探索Wix的特性,与Wix相比,它的简单性让我大吃一惊。我们已经在使用QT安装程序框架,但我们的客户也需要MSI安装包

我已经有一个目录,其中包含我们产品的所有文件,只有一个包。我试图将
C:\Temp\MyProductFiles
中的所有文件都包含到我的MSI安装程序中

using System;
using WixSharp;

class Script
{
    static public void Main(string[] args)
    {
        Compiler.WixLocation= @"C:\WiX-3.7\binaries"; 
        var project = new Project("MyProduct",
                          new Dir(@"C:\Temp\MyProduct", 
                            new DirFiles(@"C:\Temp\MyProductFiles\*.*")
                           )
                      );
        project.UI = WUI.WixUI_Common;

        Compiler.BuildMsi(project);
    }
}
安装程序基本上按预期工作,但不幸的是
C:\Temp\MyProductFiles
包含许多子目录,我不希望每次都显式地声明这些子目录,因为我们有几个产品

是否有一种简单的方法可以使用Wix自动包含所有文件和子目录


也许你也可以用C#来做,但我不精通C#,我真的不知道如何开始。

据我所知,没有内置的机制来获取所有子目录,但你可以递归遍历树,并将每个条目投影到
DirFiles

IEnumerable<string> GetSubdirectories(string root)
{
    string[] subdirectories = Directory.GetDirectories(root);
    foreach (var subdirectory in subdirectories)
    {
        yield return subdirectory;
        foreach (var nestedDirectory in GetSubdirectories(subdirectory))
        {
            yield return nestedDirectory;
        }
    }
}
然后,只需传递它:

var project = new Project("MyProduct", new Dir(@"C:\Temp\MyProduct", dirFiles)));

要包含所有文件和子目录,请使用
新文件(@“C:\Temp\MyProductFiles\*.*)
而不是
新目录文件(@“C:\Temp\MyProductFiles\*.*”

var项目=
新项目(“MyProduct”,
新目录(@“%ProgramFiles%\My Company\My Product”,
新文件(@..\Release Folder\Release\*.*))


这个问题在

中也有提到,如果您只是想获得更轻松的WiX体验,请查看:非常感谢。在使用指令添加适当的
后,它会起作用。
var project = new Project("MyProduct", new Dir(@"C:\Temp\MyProduct", dirFiles)));