示例#1
0
        /// <summary>
        /// Creates a new or uses the root directory to add the newly-created component with files being installed.
        /// </summary>
        private void ConvertFiles_AddToDirectory(FolderXml folderxml, Component wixComponent, DirectoryRef wixDirectoryRef)
        {
            if (folderxml.TargetRoot != TargetRootXml.InstallDir)
            {
                throw new InvalidOperationException(string.Format("Only the InstallDir target root is supported."));
            }

            // No relative path — nothing to create
            if (folderxml.TargetDir.Length == 0)
            {
                wixDirectoryRef.AddChild(wixComponent);
                return;
            }

            // Create the folder structure, add to the innermost
            string[]  arDirectoryChain = folderxml.TargetDir.Split('\\');
            Directory wixParentDir     = null;

            for (int a = 0; a < arDirectoryChain.Length; a++)
            {
                bool bInnermost = a == arDirectoryChain.Length - 1;                 // Whether this is the folder in which are the files itself

                // Create
                var wixDirectory = new Directory {
                    Name = arDirectoryChain[a]
                };

                // Mount self into the hierarchy
                if (wixParentDir != null)
                {
                    wixParentDir.AddChild(wixDirectory);                     // Previous dir
                }
                else
                {
                    wixDirectoryRef.AddChild(wixDirectory);                     // The very root
                }
                wixParentDir = wixDirectory;

                // Non-innermost folders get a suffix to their ID
                if (bInnermost)
                {
                    wixDirectory.Id = string.Format("{0}.{1}", DirectoryIdPrefix, folderxml.Id);
                }
                else
                {
                    wixDirectory.Id = string.Format("{0}.{1}.P{2}", DirectoryIdPrefix, folderxml.Id, arDirectoryChain.Length - 1 - a);
                }

                // Mount the component into the innermost dir
                if (bInnermost)
                {
                    wixDirectory.AddChild(wixComponent);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Actions under the resolver.
        /// </summary>
        protected override void ExecuteTaskResolved()
        {
            GuidCacheXml guidcachexml = GuidCacheXml.Load(new FileInfo(Bag.GetString(AttributeName.GuidCacheFile)).OpenRead());

            // Global structure of the WiX fragment file
            var wix = new Wix();
            var wixFragmentComponents = new Fragment();             // Fragment with the payload

            wix.AddChild(wixFragmentComponents);
            var wixDirectoryRef = new DirectoryRef();             // Mount into the directories tree, defined externally

            wixFragmentComponents.AddChild(wixDirectoryRef);
            wixDirectoryRef.Id = Bag.GetString(AttributeName.WixDirectoryId);
            var wixDirectory = new Directory();             // A locally created nameless directory that does not add any nested folders but defines the sources location

            wixDirectoryRef.AddChild(wixDirectory);
            wixDirectory.Id         = DirectoryId;
            wixDirectory.FileSource = Bag.GetString(AttributeName.ProductBinariesDir);
            var wixFragmentGroup = new Fragment();             // Fragment with the component-group that collects the components

            wix.AddChild(wixFragmentGroup);
            var wixComponentGroup = new ComponentGroup();             // ComponentGroup that collects the components

            wixFragmentGroup.AddChild(wixComponentGroup);
            wixComponentGroup.Id = Bag.GetString(AttributeName.WixComponentGroupId);

            // A component for the generated Registry entries
            var wixComponentRegistry = new Component();

            wixDirectory.AddChild(wixComponentRegistry);
            wixComponentRegistry.Id       = RegistryComponentIdPrefix;
            wixComponentRegistry.Guid     = guidcachexml[GuidIdXml.MsiComponent_ProductBinaries_Registry_Hkmu].ToString("B").ToUpper();
            wixComponentRegistry.DiskId   = Bag.Get <int>(AttributeName.DiskId);
            wixComponentRegistry.Location = Component.LocationType.local;
            var wixComponentRegistryRef = new ComponentRef();

            wixComponentGroup.AddChild(wixComponentRegistryRef);
            wixComponentRegistryRef.Id = wixComponentRegistry.Id;

            // Create the Registry key for the Plugins section
            CreatePluginsRegistryKey(wixComponentRegistry);

            // Load the AllAssemblies file
            AllAssembliesXml allassembliesxml = AllAssembliesXml.LoadFrom(Bag.Get <TaskItemByValue>(AttributeName.AllAssembliesXml).ItemSpec);

            // Tracks the files on the target machine, to prevent the same file from being installed both as an assembly and as a reference
            var mapTargetFiles = new Dictionary <string, string>();

            int nGeneratedComponents = ProcessAssemblies(wixDirectory, wixComponentGroup, wixComponentRegistry, allassembliesxml, mapTargetFiles, guidcachexml);

            // Save to the output file
            using (var xw = new XmlTextWriter(new FileStream(Bag.GetString(AttributeName.OutputFile), FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8))
            {
                xw.Formatting = Formatting.Indented;
                wix.OutputXml(xw);
            }

            // Report (also to see the target in the build logs)
            Log.LogMessage(MessageImportance.Normal, "Generated {0} product binary components.", nGeneratedComponents);
        }
示例#3
0
        /// <summary>
        /// Creates a new WiX Component for populating with the values of a specific hive, or reuses an existing one.
        /// Registry items from different hives must not be mixed within a single component.
        /// </summary>
        /// <param name="hive">Registry hive.</param>
        /// <param name="directory">A WiX directory to parent the newly-created component.</param>
        /// <param name="componentgroup">A group of components to register the newly-created component into.</param>
        protected Component GetComponentForHive(RegistryHiveXml hive, DirectoryRef directory, ComponentGroup componentgroup)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (componentgroup == null)
            {
                throw new ArgumentNullException("componentgroup");
            }

            Component component;

            if (myMapHiveToComponent.TryGetValue(hive, out component)) // Lookup
            {
                return(component);                                     // Reuse existing
            }
            // Create a new one
            component = new Component();
            myMapHiveToComponent.Add(hive, component);
            directory.AddChild(component);
            component.Id = string.Format("{0}.{1}", ComponentIdPrefix, hive);

            // Chose a GUID for the component, assign
            component.Guid = myGuidCache[GetGuidId(hive)].ToString("B").ToUpperInvariant();

            // Register in the group
            var componentref = new ComponentRef();

            componentgroup.AddChild(componentref);
            componentref.Id = component.Id;

            return(component);
        }
示例#4
0
        /// <summary>
        /// Actions under the resolver.
        /// </summary>
        protected override void ExecuteTaskResolved()
        {
            // Global structure of the WiX fragment file
            var wix = new Wix();
            var wixFragmentComponents = new Fragment();             // Fragment with the payload

            wix.AddChild(wixFragmentComponents);
            var wixDirectoryRef = new DirectoryRef();             // Mount into the directories tree, defined externally

            wixFragmentComponents.AddChild(wixDirectoryRef);
            wixDirectoryRef.Id = Bag.GetString(AttributeName.WixDirectoryId);
            var wixDirectory = new Directory();             // A locally created nameless directory that does not add any nested folders but defines the sources location

            wixDirectoryRef.AddChild(wixDirectory);
            wixDirectory.Id         = DirectoryId;
            wixDirectory.FileSource = Bag.GetString(AttributeName.ProductReferencesDir);
            var wixFragmentGroup = new Fragment();             // Fragment with the component-group that collects the components

            wix.AddChild(wixFragmentGroup);
            var wixComponentGroup = new ComponentGroup();             // ComponentGroup that collects the components

            wixFragmentGroup.AddChild(wixComponentGroup);
            wixComponentGroup.Id = Bag.GetString(AttributeName.WixComponentGroupId);

            // Load the AllAssemblies file
            AllAssembliesXml allassembliesxml = AllAssembliesXml.LoadFrom(Bag.Get <TaskItemByValue>(AttributeName.AllAssembliesXml).ItemSpec);

            // Tracks the files on the target machine, to prevent the same file from being installed both as an assembly and as a reference
            var mapTargetFiles = new Dictionary <string, string>();

            int nGeneratedComponents = ProcessReferences(wixDirectory, wixComponentGroup, allassembliesxml, mapTargetFiles);

            // Save to the output file
            using (var xw = new XmlTextWriter(new FileStream(Bag.GetString(AttributeName.OutputFile), FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8))
            {
                xw.Formatting = Formatting.Indented;
                wix.OutputXml(xw);
            }

            // Report (also to see the target in the build logs)
            Log.LogMessage(MessageImportance.Normal, "Generated {0} product reference components.", nGeneratedComponents);
        }