如何在Wix工具集中排除文件

如何在Wix工具集中排除文件,wix,heat,Wix,Heat,在获取heat.exe文件时,我想从输入文件夹中排除扩展名为.exe的文件,因为它首先获取文件夹中的所有文件 下面是我的代码 %WIX_PATH%\Heat.exe" dir "%input_folder%" -cg SourceProjectComponents -dr INSTALLLOCATION -scom -sreg -srd -var var.BasePath -gg -sfrag -var var.BasePath -out

在获取heat.exe文件时,我想从输入文件夹中排除扩展名为.exe的文件,因为它首先获取文件夹中的所有文件

下面是我的代码

    %WIX_PATH%\Heat.exe" dir "%input_folder%" -cg SourceProjectComponents 
    -dr INSTALLLOCATION -scom -sreg -srd -var var.BasePath -gg -sfrag 
    -var var.BasePath -out "%output_folder%\Output.wxs
PS:input_文件夹由几个ll.dll和.exe文件组成。因此,无法单独获取该文件


提前感谢。

您需要使用XSLT转换

像这样的事情应该适合你;只需在heat命令行中包含
-t

此XSLT输出一个新的XML文件,其中包含输入的所有XML节点,除非任何节点是具有
.exe
元素的
元素

RemoveExeComponentsTransform.xslt
我也遇到了同样的问题,我在一个项目中有很多文件需要包含在WXS文件中,我编写了一个开源命令行应用程序来生成目录结构、文件和组件的XML,同时通过.wixignore文件(格式类似于.gitignore)忽略文件夹、扩展名、文件等


如果您使用的是WiX toolset 4.0,您可以查看它。

在设置正确的命名空间(
xmlns:wix=”之前,xsl筛选器不会工作http://wixtoolset.org/schemas/v4/wxs“
) 我一直处于从3.11升级到4.0的状态,我花了几个小时才发现为什么过滤器根本不起作用。在VS解决方案或命令行(heat.exe)版本中


希望这对某人有所帮助

我喜欢WiX,但是
heat.exe
是一个比制作更难使用的工具。你可以写你自己的替代品。您只需枚举目录中的文件,然后输出一些XML。下面是一些用于启动跳过.pdb文件的代码:

foreach (string file in Directory.EnumerateFiles(directoryName))
{
    string extension = Path.GetExtension(file) ?? "";
    if (extension.Equals(".pdb", OrdinalIgnoreCase)) continue;
    string relativePath = GetRelativePath(wixProjectDirectoryName, file);
    string guid = Guid.NewGuid().ToString("D").ToUpperInvariant();
    stringBuilder.AppendLine($"<Component Id=\"Comp{fileName}\" Guid=\"{guid}\">");
    stringBuilder.AppendLine($"  <File Source=\"{relativePath}\" />");
    stringBuilder.AppendLine("</Component>");
}

public static string GetRelativePath(string baseDirectoryName, string fileFullPath)
{
    string[] absDirs = baseDirectoryName.Split('\\');
    string[] relDirs = fileFullPath.Split('\\');

    int len = absDirs.Length < relDirs.Length
        ? absDirs.Length
        : relDirs.Length;

    int lastCommonRoot = -1;
    int index;

    for (index = 0; index < len; index++)
    {
        if (absDirs[index] == relDirs[index]) lastCommonRoot = index;
        else break;
    }

    if (lastCommonRoot == -1)
        throw new ArgumentException("No common base");

    var relativePath = new StringBuilder();

    for (index = lastCommonRoot + 1; index < absDirs.Length; index++)
    {
        if (absDirs[index].Length > 0) relativePath.Append("..\\");
    }

    for (index = lastCommonRoot + 1; index < relDirs.Length - 1; index++)
        relativePath.Append(relDirs[index] + "\\");
    
    relativePath.Append(relDirs[relDirs.Length - 1]);

    return relativePath.ToString();
}
foreach(目录中的字符串文件。枚举文件(目录名))
{
字符串扩展名=Path.GetExtension(文件)?“”;
如果(extension.Equals(“.pdb”,OrdinalIgnoreCase))继续;
字符串relativePath=GetRelativePath(wixProjectDirectoryName,文件);
字符串guid=guid.NewGuid().ToString(“D”).ToUpperInvariant();
stringBuilder.AppendLine($“”);
stringBuilder.AppendLine($“”);
stringBuilder.AppendLine(“”);
}
公共静态字符串GetRelativePath(字符串baseDirectoryName,字符串fileFullPath)
{
字符串[]absDirs=baseDirectoryName.Split('\\');
字符串[]relDirs=fileFullPath.Split('\\');
int len=absDirs.Length0)relativePath.Append(“..\\”;
}
for(index=lastCommonRoot+1;index
@Michal Hainc,因为在我看来,heat.exe对用户不是很友好。就像所有的Wix一样。我仍然不明白它的作用是什么,仅仅编写一个程序是不容易做到百倍的。这种使用xlst转换进行过滤的方法是如此的困难和不直观,它迫切需要。我编辑了这个答案,使用XSLT 1.0
样式匹配结束,而不是使用
包含(…,'.exe'))
因为否则
app.config
文件(例如
Foo.Bar.exe.config
)将被删除,这可能不是您想要的,因为这将导致绑定重定向被删除,例如(这发生在我身上,花了很长时间才弄清楚原因!)
foreach (string file in Directory.EnumerateFiles(directoryName))
{
    string extension = Path.GetExtension(file) ?? "";
    if (extension.Equals(".pdb", OrdinalIgnoreCase)) continue;
    string relativePath = GetRelativePath(wixProjectDirectoryName, file);
    string guid = Guid.NewGuid().ToString("D").ToUpperInvariant();
    stringBuilder.AppendLine($"<Component Id=\"Comp{fileName}\" Guid=\"{guid}\">");
    stringBuilder.AppendLine($"  <File Source=\"{relativePath}\" />");
    stringBuilder.AppendLine("</Component>");
}

public static string GetRelativePath(string baseDirectoryName, string fileFullPath)
{
    string[] absDirs = baseDirectoryName.Split('\\');
    string[] relDirs = fileFullPath.Split('\\');

    int len = absDirs.Length < relDirs.Length
        ? absDirs.Length
        : relDirs.Length;

    int lastCommonRoot = -1;
    int index;

    for (index = 0; index < len; index++)
    {
        if (absDirs[index] == relDirs[index]) lastCommonRoot = index;
        else break;
    }

    if (lastCommonRoot == -1)
        throw new ArgumentException("No common base");

    var relativePath = new StringBuilder();

    for (index = lastCommonRoot + 1; index < absDirs.Length; index++)
    {
        if (absDirs[index].Length > 0) relativePath.Append("..\\");
    }

    for (index = lastCommonRoot + 1; index < relDirs.Length - 1; index++)
        relativePath.Append(relDirs[index] + "\\");
    
    relativePath.Append(relDirs[relDirs.Length - 1]);

    return relativePath.ToString();
}