public override bool Execute() { try { XmlDocument wiXDoc = new XmlDocument(); wiXDoc.Load(new FileStream(wixFile, FileMode.Open, FileAccess.Read)); string outputPath = Path.GetDirectoryName(compressFileName); if (!outputPath.EndsWith("\\")) { outputPath += "\\"; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(wiXDoc.NameTable); nsmgr.AddNamespace( "ns", wiXDoc.DocumentElement.Attributes["xmlns"].Value); XmlNode rootDirNode = wiXDoc.SelectSingleNode( string.Format("/descendant::ns:Fragment/ns:DirectoryRef[@Id=\"{0}\"]/ns:Directory", parentDirectoryRef), nsmgr); string zipDirectory = CreateDirectory(rootDirNode, outputPath); string xPath = "/descendant::ns:Fragment/ns:DirectoryRef/ns:Directory/ns:Component/ns:File"; foreach (XmlNode fileNode in wiXDoc.SelectNodes(xPath, nsmgr)) { CopyFile(fileNode); } string currentDirectory = Environment.CurrentDirectory; Environment.CurrentDirectory = Path.GetDirectoryName(outputPath); SetReadWrite(outputPath + zipDirectory); CreateZip zip = new CreateZip(); zip.BuildEngine = BuildEngine; zip.HostObject = HostObject; zip.InputDirectories = new Microsoft.Build.Framework.ITaskItem[] { new Microsoft.Build.Utilities.TaskItem(zipDirectory) }; zip.OutputFile = compressFileName; zip.Execute(); Directory.Delete(outputPath + zipDirectory, true); Environment.CurrentDirectory = currentDirectory; } catch (Exception ex) { Console.WriteLine("***Exception: " + ex.ToString()); return false; } return true; }
public override bool Execute() { try { XmlDocument wiXDoc = new XmlDocument(); wiXDoc.Load(new FileStream(wixFile, FileMode.Open, FileAccess.Read)); string outputPath = Path.GetDirectoryName(compressFileName); if (!outputPath.EndsWith("\\")) { outputPath += "\\"; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(wiXDoc.NameTable); nsmgr.AddNamespace( "ns", wiXDoc.DocumentElement.Attributes["xmlns"].Value); XmlNode rootDirNode = wiXDoc.SelectSingleNode( string.Format("/descendant::ns:Fragment/ns:DirectoryRef[@Id=\"{0}\"]/ns:Directory", parentDirectoryRef), nsmgr); string zipDirectory = CreateDirectory(rootDirNode, outputPath); string xPath = "/descendant::ns:Fragment/ns:DirectoryRef/ns:Directory/ns:Component/ns:File"; foreach (XmlNode fileNode in wiXDoc.SelectNodes(xPath, nsmgr)) { CopyFile(fileNode); } string currentDirectory = Environment.CurrentDirectory; Environment.CurrentDirectory = Path.GetDirectoryName(outputPath); SetReadWrite(outputPath + zipDirectory); CreateZip zip = new CreateZip(); zip.BuildEngine = BuildEngine; zip.HostObject = HostObject; zip.InputDirectories = new Microsoft.Build.Framework.ITaskItem[] { new Microsoft.Build.Utilities.TaskItem(zipDirectory) }; zip.OutputFile = compressFileName; zip.Execute(); Directory.Delete(outputPath + zipDirectory, true); Environment.CurrentDirectory = currentDirectory; } catch (Exception ex) { Console.WriteLine("***Exception: " + ex.ToString()); return(false); } return(true); }