public Result <int> Folder2Wxs(HarvestInfo harvestInfo) { try { _folder2Wxs.Harvest(harvestInfo); return(Result.Ok(0)); } catch (Exception e) { return(Result.Fail <int>(new NMultiToolException($"Failed to harvest folder '{harvestInfo.Path.Value}'. {e.Message}", e))); } }
public void Harvest(HarvestInfo harvestInfo) { if (!harvestInfo.EnableKeyPath) { if (string.IsNullOrWhiteSpace(harvestInfo.CompanyName)) { throw new ArgumentException("/companyName must be specified on the command line."); } if (string.IsNullOrWhiteSpace(harvestInfo.ApplicationName)) { throw new ArgumentException("/applicationName must be specified on the command line."); } } if (_logger.IsInfoEnabled) { _logger.InfoFormat("Harvesting to wsx from directory '{0}'...", harvestInfo.Path.Value); } var wsxXmlDocument = new XmlDocument(); var xmlDeclaration = wsxXmlDocument.CreateXmlDeclaration("1.0", "utf-8", String.Empty); wsxXmlDocument.AppendChild(xmlDeclaration); wsxXmlDocument.AppendChild(wsxXmlDocument.CreateProcessingInstruction("if", $"$(var.Platform) = x64")); wsxXmlDocument.AppendChild(wsxXmlDocument.CreateProcessingInstruction("define", $"bitness = \"(64 bit)\"")); wsxXmlDocument.AppendChild(wsxXmlDocument.CreateProcessingInstruction("define", $"Win64 = \"yes\"")); wsxXmlDocument.AppendChild(wsxXmlDocument.CreateProcessingInstruction("else", string.Empty)); wsxXmlDocument.AppendChild(wsxXmlDocument.CreateProcessingInstruction("define", $"bitness = \"(32 bit)\"")); wsxXmlDocument.AppendChild(wsxXmlDocument.CreateProcessingInstruction("define", $"Win64 = \"no\"")); wsxXmlDocument.AppendChild(wsxXmlDocument.CreateProcessingInstruction("endif", string.Empty)); var wsxRootElement = wsxXmlDocument.CreateElement("Wix"); wsxXmlDocument.AppendChild(wsxRootElement); _xmlHelper.SetAttribute(wsxXmlDocument.DocumentElement, "xmlns", "http://schemas.microsoft.com/wix/2006/wi"); if (wsxXmlDocument.DocumentElement == null) { throw new XmlException("xmldocument document element is null"); } var fragment1 = wsxXmlDocument.CreateElement("Fragment"); if (wsxXmlDocument.DocumentElement == null) { throw new XmlException("xmldocument document element is null"); } wsxXmlDocument.DocumentElement.AppendChild(fragment1); var fragment2 = wsxXmlDocument.CreateElement("Fragment"); if (wsxXmlDocument.DocumentElement == null) { throw new XmlException("xmldocument document element is null"); } wsxXmlDocument.DocumentElement.AppendChild(fragment2); var componentGroupXmlNode = wsxXmlDocument.CreateElement("ComponentGroup"); _xmlHelper.SetAttribute(componentGroupXmlNode, "Id", harvestInfo.ComponentGroupId); fragment2.AppendChild(componentGroupXmlNode); var directoryRefElement = wsxXmlDocument.CreateElement("DirectoryRef"); _xmlHelper.SetAttribute(directoryRefElement, "Id", harvestInfo.TargetFolderId); fragment1.AppendChild(directoryRefElement); AddDirectory(new DirectoryInfo(harvestInfo.Path.Value), directoryRefElement, componentGroupXmlNode, harvestInfo.TargetFolderId, harvestInfo.DiskIds, harvestInfo.AddExecutables2AppsPath, harvestInfo.EnableKeyPath, harvestInfo.CompanyName, harvestInfo.ApplicationName, harvestInfo.IsWin64.Value); _xmlHelper.SaveDocument(wsxXmlDocument, harvestInfo.WsxFileName); if (_logger.IsInfoEnabled) { _logger.InfoFormat("Finished harvesting to wsx from directory '{0}'...", harvestInfo.Path.Value); } }