Пример #1
0
 public void LoadWix(string fileName)
 {
     using (StreamReader reader = new StreamReader(fileName))
     {
         this.wix = (Wix)this.serializer.Deserialize(reader);
     }
 }
Пример #2
0
        private void Compile(Compiler compiler, string name, Wix wix)
        {
            // Load the wix document into an XML document.

            XmlDocument xmlDocument = new XmlDocument();

            using (MemoryStream writerStream = new MemoryStream())
            {
                using (XmlTextWriter xmlWriter = new XmlTextWriter(writerStream, Encoding.Unicode))
                {
                    wix.OutputXml(xmlWriter);
                }

                using (MemoryStream readerStream = new MemoryStream(writerStream.GetBuffer()))
                {
                    xmlDocument.Load(readerStream);
                }
            }

            // Compile it.

            Intermediate intermediate = compiler.Compile(xmlDocument);

            // Save the intermediate.

            string path = Path.Combine(m_buildFolder, name + File.Wixobj.Extension);

            intermediate.Save(path);
        }
Пример #3
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);
        }
Пример #4
0
        private static void WriteWxsFile(string sOutputWxs, List <RegistryKey> wixKeys, List <RegistryValue> wixValues)
        {
            var wix         = new Wix();
            var wixFragment = new Fragment();

            wix.AddChild(wixFragment);
            var wixDirectory = new Directory();

            wixFragment.AddChild(wixDirectory);
            wixDirectory.Id = "";
            var wixComponent = new Component();

            wixDirectory.AddChild(wixComponent);
            wixComponent.Id   = "";
            wixComponent.Guid = "*";

            foreach (RegistryKey wixKey in wixKeys)
            {
                wixComponent.AddChild(wixKey);
            }
            foreach (RegistryValue wixValue in wixValues)
            {
                wixComponent.AddChild(wixValue);
            }

            // Save to the output file
            using (var xw = new XmlTextWriter(new FileStream(sOutputWxs, FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8))
            {
                xw.Formatting = Formatting.Indented;
                wix.OutputXml(xw);
            }
        }
Пример #5
0
        private void CreateDirectories(Wix model)
        {
            var dir = new DirectoryInfo(InstallDirPath);

            model.Fragment.Directories = new List <DirectoryElement>
            {
                CreateSubDir(dir)
            };
        }
Пример #6
0
 public virtual void VisitWix(Wix wix)
 {
     if (wix == null)
     {
         throw new ArgumentNullException("wix");
     }
     VisitItem(wix.Item);
     VisitFragmentArray(wix.Fragment);
 }
Пример #7
0
 /// <summary>
 /// Creates a new Application object.
 /// </summary>
 public Application()
 {
     this.wixRoot = new Wix();
     this.product = new Product();
     this.wixRoot.AddChild(this.product);
     this.package                  = new Package();
     this.package.Id               = "????????-????-????-????-????????????";
     this.package.Compressed       = WixToolset.Serialize.YesNoType.yes;
     this.package.InstallerVersion = 200;
     this.product.AddChild(this.package);
 }
Пример #8
0
        private bool SerializeXml()
        {
            try
            {
                var filesTree = Directory.EnumerateFiles(InstallDirPath, "*", SearchOption.AllDirectories).ToList();

                var model = new Wix {
                    Fragment = new FragmentElement()
                };
                CreateWixComponents(model, filesTree);
                CreateDirectories(model);

                var serializer = new XmlSerializer(model.GetType());
                using (var file = new FileStream("Components.wxs", FileMode.Create, FileAccess.Write))
                    using (var writer = new StreamWriter(file))
                    {
                        var namespaces = new XmlSerializerNamespaces();
                        namespaces.Add("x", @"http://schemas.microsoft.com/wix/2006/wi");
                        serializer.Serialize(writer, model, namespaces);
                    }

                return(true);
            }
            catch (Exception ex)
            {
                using (var file = new FileStream("Components.wxs", FileMode.Create, FileAccess.Write))
                    using (var writer = new StreamWriter(file))
                    {
                        writer.WriteLine("Message:");
                        writer.WriteLine(ex.Message);
                        writer.WriteLine();

                        writer.WriteLine("StackTrace:");
                        writer.WriteLine(ex.StackTrace);
                        writer.WriteLine();

                        writer.WriteLine("Source:");
                        writer.WriteLine(ex.Source);
                        writer.WriteLine();

                        var info =
                            "Source files directory: " + SolutionDirPath + "\n" +
                            "INSTALLDIR: " + InstallDirPath + "\n" +
                            "Current file path: " + currentFilePath;

                        writer.WriteLine("Info: ");
                        writer.WriteLine(info);
                    }
                return(false);
            }
        }
Пример #9
0
        public void Load(bool isWin64, Catalogue catalogue)
        {
            // Get the root folder path.

            string rootFolderPath;

            if (string.IsNullOrEmpty(catalogue.RootFolder))
            {
                rootFolderPath = Path.GetDirectoryName(catalogue.FullPath);
            }
            else
            {
                rootFolderPath = FilePath.GetAbsolutePath(catalogue.RootFolder, Path.GetDirectoryName(catalogue.FullPath));
            }

            // Create the module element.

            Module module = CreateModule();

            Wix.AddChild(module);

            // Create the package element.

            Microsoft.Tools.WindowsInstallerXml.Serialize.Package package = CreatePackage(isWin64);
            module.AddChild(package);

            // Create a target directory element.

            Directory directory = CreateDirectory(Constants.Wix.Xml.Directory.Target.Id, Constants.Wix.Xml.Directory.Target.Name);

            module.AddChild(directory);

            // Load the artifacts in the catalogue.

            foreach (Artifact artifact in catalogue.Artifacts)
            {
                Load(isWin64, artifact, rootFolderPath, directory);
            }

            // Add the catalogue file itself.

            Artifact catalogueArtifact = new Artifact(FilePath.GetRelativePath(catalogue.FullPath, rootFolderPath));

            catalogueArtifact.SetMetadata(Constants.Catalogue.Artifact.Guid, catalogue.Guid);
            Load(isWin64, catalogueArtifact, rootFolderPath, directory);

            // Resolve all elements.

            Resolve(directory);
        }
Пример #10
0
        private static void Init()
        {
            wix               = new Wix(); Product = new Product(); Feature = new Feature();
            TargetDirectory   = new Directory(); InstallDirectory = new Directory();
            CustomActionItems = null; UILocalizedFile = "WixUI_en-us.wxl";
            RegistryComponents.Clear(); UIRef.Clear(); PropertyElements.Clear();
            ProductMiscElements.Clear(); FeatureTable.Clear(); EnvironmentComponents.Clear();
            ConditionElements.Clear(); MsiCompiler.BootstrapperName = string.Empty;

            // delete all *.url files
            string[] files = IO.Directory.GetFiles(Globals.localFolder, "*.url");
            foreach (string filePath in files)
            {
                IO.File.Delete(filePath);
            }
        }
Пример #11
0
        private void CreateWixComponents(Wix model, List <string> filesTree)
        {
            try
            {
                model.Fragment.ComponentGroup = new ComponentGroupElement {
                    Id = $"{ Working.RemoveIllegalCharacters(InstallDirPath.Substring(InstallDirPath.LastIndexOf('\\') + 1)) }FileComponents"
                };
                model.Fragment.ComponentGroup.Components = new List <ComponentElement>();

                var format     = Working.GetToStringFormat(filesTree.Count);
                var components = model.Fragment.ComponentGroup.Components;
                foreach (var filePath in filesTree)
                {
                    var i                  = components.Count + 1;
                    var count              = i.ToString(format);
                    var fileName           = Path.GetFileName(filePath);
                    var componentDirectory = Working.GetSubDirPath(InstallDirPath, filePath);
                    componentDirectory = componentDirectory.Substring(0, componentDirectory.Length - fileName.Length - 1).Replace('\\', '_');
                    var component = new ComponentElement
                    {
                        Id        = Working.RemoveIllegalCharacters($"IDC_{ fileName }_{ count }"),
                        Directory = Working.RemoveIllegalCharacters($"IDD_{ componentDirectory }"),
                        Guid      = ShouldGenerateGuids ? Guid.NewGuid().ToString().ToUpper() : "*",
                        Win64     = ShouldPrepareX64Components ? "yes" : "no"
                    };

                    var file = new FileElement
                    {
                        Id      = Working.RemoveIllegalCharacters($"IDF_{ fileName }_{ count }"),
                        Name    = fileName,
                        DiskId  = "1",
                        Source  = $"$(var.SolutionDir){ Working.GetSubDirPath(InstallDirPath, filePath) }",
                        KeyPath = "yes"
                    };

                    component.File = file;
                    components.Add(component);
                }
            }
            catch (Exception ex)
            {
                var message = "Exception thrown in CreateWixComponents()\n";
                throw new Exception(message, ex);
            }
        }
Пример #12
0
        /// <summary>
        /// Actions under the resolver.
        /// </summary>
        protected override void ExecuteTaskResolved()
        {
            // Prepare the GUID cache
            myGuidCache = 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 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);

            // Get the dump from the product
            InstallationDataXml          dataxml = CreateInstaller().HarvestInstallationData();
            IDictionary <string, string> macros  = GetMacros();

            // Nullref guards
            dataxml.AssertValid();

            // Convert into WiX
            int nProducedFiles  = ConvertFiles(wixDirectoryRef, wixComponentGroup, dataxml, macros);
            int nProducedKeys   = ConvertRegistryKeys(wixDirectoryRef, wixComponentGroup, dataxml, macros);
            int nProducedValues = ConvertRegistryValues(wixDirectoryRef, wixComponentGroup, dataxml, macros);

            // 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} files, {1} Registry keys, and {2} Registry values.", nProducedFiles, nProducedKeys, nProducedValues);
        }
Пример #13
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);
        }
Пример #14
0
        public WixRenderer()
        {
            this.graph = new AdjacencyGraph(
                new CustomVertexProvider(),
                new CustomEdgeProvider(),
                true
                );
            this.graphviz = new GraphvizAlgorithm(this.graph);
            this.wix      = null;

            this.graphviz.ImageType                    = NGraphviz.Helpers.GraphvizImageType.Svg;
            this.graphviz.CommonEdgeFormat.Font        = new Font("Tahoma", 8.25f);
            this.graphviz.CommonVertexFormat.Font      = new Font("Tahoma", 8.25f);
            this.graphviz.CommonVertexFormat.Style     = NGraphviz.Helpers.GraphvizVertexStyle.Filled;
            this.graphviz.CommonVertexFormat.FillColor = Color.LightYellow;
            this.graphviz.CommonVertexFormat.Shape     = NGraphviz.Helpers.GraphvizVertexShape.Box;
            this.graphviz.FormatVertex                += new FormatVertexEventHandler(graphviz_FormatVertex);

            this.visitor = new GraphPopulatorWixVisitor(this);
        }