private void AddFile(string fileName, ProjectEx project, WiXDirectory projectDirectory, Component component, Hashtable componentFiles) { string fullPath = project.GetFullPath(fileName); WiXDirectory fileParent = null; // If we have any project sub folders add them now. string addDirPath = Path.GetDirectoryName(fileName); fileParent = AddFolder( projectDirectory, component, addDirPath); WiXFile wixFile = null; if (componentFiles.ContainsKey(fullPath)) { wixFile = componentFiles[fullPath] as WiXFile; } else { wixFile = new WiXFile(component, fullPath); componentFiles.Add(fullPath, wixFile); } // Have WiX copy the file to the final destination wixFile.CopyFile(fileParent.Id, Path.GetFileName(fileName)); }
private WiXDirectory AddFolder(WiXDirectory topDirectory, Component component, string path) { if (path == "") { return(topDirectory); } // Recursion here: WiXDirectory parent = AddFolder(topDirectory, component, Path.GetDirectoryName(path)); // If we already added this folder then reuse it. WiXDirectory thisFolder = parent.GetDirectoryFromName(Path.GetFileName(path)); if (thisFolder == null) { thisFolder = new WiXDirectory(parent, Path.GetFileName(path)); thisFolder.Id = solutionName + "_" + thisFolder.Id; component.CreateFolder(thisFolder); } return(thisFolder); }
public Shortcut(Component component, Directory target, string name, DirectoryRef directory) :this(component, (WiXElement)target, name, directory) { }
public Directory(Directory parent, string name, string Id) : this(parent.Element, name, Id) { }
public void Save( string slnFile, string wxsFile, Guid componentGuid) { base.Save(slnFile); this.Add(new SolutionObject(SolutionFile.CreateDotSln(slnFile))); Hashtable componentFiles = new Hashtable(); solutionName = Path.GetFileNameWithoutExtension(slnFile); Fragment fragment = new Fragment("Fragment_" + solutionName); m_SolutionFragment = fragment; if (fragmentIncludeFiles != null) { foreach (ITaskItem fragmentInclude in fragmentIncludeFiles) { fragment.PrependInclude(fragmentInclude.ItemSpec); } } DirectoryRef samplesRef = new DirectoryRef(fragment, parentDirectoryRef); WiXDirectory solutionDir = new WiXDirectory(samplesRef, solutionName); solutionDir.Id = solutionName + "_" + solutionDir.Id; DirectoryRef tempRef = new DirectoryRef(fragment, "TEMPFOLDERINSTALLDIR"); WiXDirectory tempSlnDir = new WiXDirectory(tempRef, solutionName); tempSlnDir.Id = solutionName + "_" + tempSlnDir.Id; Component component = new Component(tempSlnDir, "Component_" + solutionName, componentGuid); if (shortcut == ShortcutType.FOLDER) { Shortcut folderShortcut = new Shortcut( component, solutionDir, solutionName, new DirectoryRef(fragment, "ProgramMenuDir")); folderShortcut.Id = solutionName + "_" + folderShortcut.Id; } foreach (SolutionObject slnObj in this) { if (slnObj.Object is ProjectEx) { #region ProjectEx ProjectEx project = slnObj.Object as ProjectEx; // Add the project folder to the WiX file string projectFolderName = Path.GetFileNameWithoutExtension(project.FullFileName); WiXDirectory projectDirectory = new WiXDirectory(solutionDir, projectFolderName); projectDirectory.Id = solutionName + "_" + projectDirectory.Id; component.CreateFolder(projectDirectory); WiXFile projectFile = new WiXFile(component, Path.Combine(Path.GetDirectoryName(wxsFile), Path.GetFileName(project.FullFileName))); projectFile.CopyFile(projectDirectory.Id); // Add subfolders foreach (_BE.ProjectItem folderItem in project.MsBuildProject.GetItems("Folder")) { string addDirPath = folderItem.Xml.Include; if (addDirPath.EndsWith(Path.DirectorySeparatorChar.ToString())) { addDirPath = addDirPath.Substring(0, addDirPath.Length - 1); } AddFolder( projectDirectory, component, addDirPath); } // Loop through all known item groups that map to files // and add those files. foreach (string groupName in ProjectEx.FileGroups) { foreach (_BE.ProjectItem buildItem in project.MsBuildProject.GetItems(groupName)) { AddFile( buildItem.Xml.Include, project, projectDirectory, component, componentFiles); } } foreach (string extraFile in project.ExtraFiles) { AddFile( extraFile, project, projectDirectory, component, componentFiles); } #endregion } else { #region SolutionFile SolutionFile slnFileObj = slnObj.Object as SolutionFile; WiXFile slnFileElem = new WiXFile(component, slnFileObj.File); slnFileElem.Id = solutionName + "_" + slnFileElem.Id; slnFileElem.CopyFile(solutionDir.Id); if (slnFileObj.IsDotSln && shortcut == ShortcutType.DOTSLN) { Shortcut dotSlnShortcut = new Shortcut( slnFileElem, Path.GetFileNameWithoutExtension(slnFileElem.Name), new DirectoryRef(fragment, "ProgramMenuDir")); dotSlnShortcut.Id = solutionName + "_" + dotSlnShortcut.Id; } #endregion } } if (componentIncludeFiles != null) { foreach (ITaskItem componentInclude in componentIncludeFiles) { component.AppendInclude(componentInclude.ItemSpec); } } fragment.Element.OwnerDocument.Save(wxsFile); }
public DirectoryRef(Fragment parent, Directory source) : base(parent.Element, "DirectoryRef", source.Id) { }
public CreateFolder(Component component, Directory directory) : this(component, directory.Id) { }
public void CreateFolder(Directory directory) { new CreateFolder(this, directory); }
public Component(Directory parent, string Id, Guid guid) : this(parent.Element, Id, guid) { }
public Component(Directory parent) : this(parent, "component" + componentCount++, Guid.NewGuid()) { }