public FileMapping([NotNull] ProjectOutputGroup projectOutputGroup, [NotNull] ObservableCollection <ProjectOutputGroup> allUnmappedProjectOutputs, [NotNull] WixProject wixProject, [NotNull] IList <UnmappedFile> allUnmappedFiles) { _projectOutputGroup = projectOutputGroup; _allUnmappedProjectOutputs = allUnmappedProjectOutputs; _wixProject = wixProject; _allUnmappedFiles = allUnmappedFiles; Id = wixProject.GetFileId(TargetName); MappedNode = wixProject.FileNodes.FirstOrDefault(node => node.Id == Id); _unmappedProjectOutputs = new ObservableFilteredCollection <ProjectOutputGroup>(_allUnmappedProjectOutputs, item => string.Equals(item?.FileName, DisplayName, StringComparison.OrdinalIgnoreCase)); _unmappedProjectOutputs.CollectionChanged += UnmappedProjectOutputs_CollectionChanged; _unmappedFiles = new ObservableFilteredCollection <UnmappedFile>(allUnmappedFiles, item => string.Equals(item?.Node.Name, DisplayName, StringComparison.OrdinalIgnoreCase)); _unmappedFiles.CollectionChanged += UnmappedNodes_CollectionChanged; UpdateMappingState(); }
/// <summary> /// Creates WiX fragments for files in one output group. /// </summary> /// <param name="projectFile">VS MSBuild project file.</param> /// <param name="buildOutputs">Dictionary of build outputs retrieved from an MSBuild run on the project file.</param> /// <param name="pog">Project output group parameters.</param> /// <param name="fragmentList">List to which generated fragments will be added.</param> /// <returns>Count of harvested files.</returns> private int HarvestProjectOutputGroup(string projectFile, IDictionary buildOutputs, ProjectOutputGroup pog, IList fragmentList) { string projectName = Path.GetFileNameWithoutExtension(projectFile); string projectBaseDir = null; if (this.ProjectName != null) { projectName = this.ProjectName; } string sanitizedProjectName = HarvesterCore.GetIdentifierFromName(projectName); Wix.IParentElement harvestParent; if (this.GenerateType == GenerateType.Container) { Wix.Container container = new Wix.Container(); harvestParent = container; container.Name = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else if (this.GenerateType == GenerateType.PayloadGroup) { Wix.PayloadGroup container = new Wix.PayloadGroup(); harvestParent = container; container.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else if (this.GenerateType == GenerateType.PackageGroup) { Wix.PackageGroup container = new Wix.PackageGroup(); harvestParent = container; container.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else { Wix.DirectoryRef directoryRef = new Wix.DirectoryRef(); harvestParent = directoryRef; if (!String.IsNullOrEmpty(this.directoryIds)) { directoryRef.Id = this.directoryIds; } else if (this.setUniqueIdentifiers) { directoryRef.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else { directoryRef.Id = HarvesterCore.GetIdentifierFromName(String.Format(CultureInfo.InvariantCulture, VSProjectHarvester.DirectoryIdFormat, sanitizedProjectName, pog.Name)); } this.directoryRefSeed = this.Core.GenerateIdentifier(DirectoryPrefix, this.projectGUID, pog.Name); } IEnumerable pogFiles = buildOutputs[pog.BuildOutputGroup] as IEnumerable; if (pogFiles == null) { throw new WixException(VSErrors.MissingProjectOutputGroup( projectFile, pog.BuildOutputGroup)); } if (pog.FileSource == "ProjectDir") { projectBaseDir = Path.GetDirectoryName(projectFile) + "\\"; } int harvestCount = this.HarvestProjectOutputGroupFiles(projectBaseDir, projectName, pog.Name, pog.FileSource, pogFiles, harvestParent); if (this.GenerateType == GenerateType.Container) { // harvestParent must be a Container at this point Wix.Container container = harvestParent as Wix.Container; Wix.Fragment fragment = new Wix.Fragment(); fragment.AddChild(container); fragmentList.Add(fragment); } else if (this.GenerateType == GenerateType.PackageGroup) { // harvestParent must be a PackageGroup at this point Wix.PackageGroup packageGroup = harvestParent as Wix.PackageGroup; Wix.Fragment fragment = new Wix.Fragment(); fragment.AddChild(packageGroup); fragmentList.Add(fragment); } else if (this.GenerateType == GenerateType.PayloadGroup) { // harvestParent must be a Container at this point Wix.PayloadGroup payloadGroup = harvestParent as Wix.PayloadGroup; Wix.Fragment fragment = new Wix.Fragment(); fragment.AddChild(payloadGroup); fragmentList.Add(fragment); } else { // harvestParent must be a DirectoryRef at this point Wix.DirectoryRef directoryRef = harvestParent as Wix.DirectoryRef; if (harvestCount > 0) { Wix.Fragment drf = new Wix.Fragment(); drf.AddChild(directoryRef); fragmentList.Add(drf); } Wix.ComponentGroup cg = new Wix.ComponentGroup(); if (this.setUniqueIdentifiers || !String.IsNullOrEmpty(this.directoryIds)) { cg.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name); } else { cg.Id = directoryRef.Id; } if (harvestCount > 0) { this.AddComponentsToComponentGroup(directoryRef, cg); } Wix.Fragment cgf = new Wix.Fragment(); cgf.AddChild(cg); fragmentList.Add(cgf); } return harvestCount; }
/// <summary> /// Harvest a VS project. /// </summary> /// <param name="argument">The path of the VS project file.</param> /// <returns>The harvested directory.</returns> public override Wix.Fragment[] Harvest(string argument) { if (null == argument) { throw new ArgumentNullException("argument"); } if (!File.Exists(argument)) { throw new FileNotFoundException(argument); } // Match specified output group names to available POG structures // and collect list of build output groups to pass to MSBuild. ProjectOutputGroup[] pogs = new ProjectOutputGroup[this.outputGroups.Length]; string[] buildOutputGroups = new string[this.outputGroups.Length]; for (int i = 0; i < this.outputGroups.Length; i++) { foreach (ProjectOutputGroup pog in VSProjectHarvester.allOutputGroups) { if (pog.Name == this.outputGroups[i]) { pogs[i] = pog; buildOutputGroups[i] = pog.BuildOutputGroup; } } if (buildOutputGroups[i] == null) { throw new WixException(VSErrors.InvalidOutputGroup(this.outputGroups[i])); } } string projectFile = Path.GetFullPath(argument); IDictionary buildOutputs = this.GetProjectBuildOutputs(projectFile, buildOutputGroups); ArrayList fragmentList = new ArrayList(); for (int i = 0; i < pogs.Length; i++) { this.HarvestProjectOutputGroup(projectFile, buildOutputs, pogs[i], fragmentList); } return (Wix.Fragment[]) fragmentList.ToArray(typeof(Wix.Fragment)); }