How is HeatDirectory 2 or more times against directories with the same files?

I used the HeatDirectory task in our WiX installation project in the BeforeBuild target environment to collect the files of the web application that we deploy on the client network. Worked great.

Now I want to deploy a second set of files, which turned out to be some documentation, and it contains files with the same name that existed in the previous HeatDirectory release.

I get the following error:

LGHT0293: Multiple files with ID 'Web.Config' exist.

I understand why I get an error, I wonder how best to resolve it.

Option A :

Copy all the files into a directory and run them in one massive pass.

I like it because it would be pretty easy to implement using MSBuild tasks. I don’t like it because it will create one massive ComponentGroup, and if I ever want to make additional functions (for example, not to install something), I cannot.

Option B :

Iterate over the HeatDirectory task output file and add a suffix to all component identifiers and the file identifier. Example. Web.config will become web.config_DocumenationFiles

I like it because it is clean; that is, I can delete it later or add it to a project that has a problem, and not add it to projects that do not. I don’t like it because I’m not sure that the “process” (or the MSBuild task) is able to do this. I need a special task, I think.

:?

?

+3
2

, - . , , Option B, MSBuild .

, / , .

, HeatDirectory, Id.

<AddSuffixToHeatDirectory File="ReportFiles.Generated.wxs" Suffix="_r" />

AddSuffixToHeatDirectory

public class AddSuffixToHeatDirectory : Task
{
    public override bool Execute()
    {
        bool result = true;

        Log.LogMessage("Opening file '{0}'.", File);
        var document = XElement.Load(File);

        var defaultNamespace = GetDefaultNamespace(document);

        AddSuffixToAttribute(document, defaultNamespace, "Component", "Id");
        AddSuffixToAttribute(document, defaultNamespace, "File", "Id");
        AddSuffixToAttribute(document, defaultNamespace, "ComponentRef", "Id");
        AddSuffixToAttribute(document, defaultNamespace, "Directory", "Id");

        var files = (from x in document.Descendants(defaultNamespace.GetName("File")) select x).ToList();

        Log.LogMessage("Saving file '{0}'.", File);
        document.Save(File);

        return result;
    }

    private void AddSuffixToAttribute(XElement xml, XNamespace defaultNamespace, string elementName, string attributeName)
    {
        var items = (from x in xml.Descendants(defaultNamespace.GetName(elementName)) select x).ToList();
        foreach (var item in items)
        {
            var attribute = item.Attribute(attributeName);
            attribute.Value = string.Format("{0}{1}", attribute.Value, Suffix);
        }
    }

    private XNamespace GetDefaultNamespace(XElement root)
    {
        // I pieced together this query from hanselman post.
        //  http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx
        // 
        // Basically I'm just getting the namespace that doesn't have a localname.
        var result = root.Attributes()
                        .Where(a => a.IsNamespaceDeclaration)
                        .GroupBy(a => a.Name.Namespace == XNamespace.None ? String.Empty : a.Name.LocalName, a => XNamespace.Get(a.Value))
                        .ToDictionary(g => g.Key, g => g.First());
        return result[string.Empty];
    }

    /// <summary>
    /// File to modify.
    /// </summary>
    [Required]
    public string File { get; set; }

    /// <summary>
    /// Suffix to append.
    /// </summary>
    [Required]
    public string Suffix { get; set; }
}

, . , , Transform HeatDirectory.

+1

HeatDirectory Transforms , . xslt, .

, Heat . , .

+4

Source: https://habr.com/ru/post/1791029/


All Articles