Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an installer based on the <see cref="AttributeName.AllAssembliesXml"/> list.
        /// </summary>
        protected Installer CreateInstaller()
        {
            // Load the AllAssemblies file
            AllAssembliesXml allassembliesxml = AllAssembliesXml.LoadFrom(Bag.Get <TaskItemByValue>(AttributeName.AllAssembliesXml).ItemSpec);

            // Get the list of assemblies
            var assemblies = new List <Assembly>();

            foreach (ItemGroupXml group in allassembliesxml.ItemGroup)
            {
                if (group.AllAssemblies == null)
                {
                    continue;
                }
                foreach (AssemblyXml assemblyxml in group.AllAssemblies)
                {
                    FileInfo fiAssembly = FindAssemblyFile(assemblyxml);

                    // Check whether it's a managed or native assembly
                    AssemblyName assemblyname = null;
                    try
                    {
                        assemblyname = AssemblyName.GetAssemblyName(fiAssembly.FullName);
                    }
                    catch (BadImageFormatException)
                    {
                    }

                    if (assemblyname == null)
                    {
                        continue;                         // Not a managed assembly
                    }
                    // Collect
                    assemblies.Add(Assembly.LoadFrom(fiAssembly.FullName));
                }
            }

            return(new Installer(assemblies));
        }