Пример #1
0
        /// <summary>
        /// Builds the WiX source file (*.wxs) from the specified <see cref="Project"/> instance.
        /// </summary>
        /// <param name="path">The path to the WXS file to be build.</param>
        /// <param name="type">The type (<see cref="Compiler.OutputType"/>) of the setup file to be defined in the source file (MSI vs. MSM).</param>
        /// <returns>Path to the built WXS file.</returns>
        public string BuildWxs(Compiler.OutputType type = Compiler.OutputType.MSI, string path = null)
        {
            if (Compiler.ClientAssembly.IsEmpty())
                Compiler.ClientAssembly = System.Reflection.Assembly.GetCallingAssembly().Location;

            if (path == null)
                return Compiler.BuildWxs(this, type);
            else
                return Compiler.BuildWxs(this, path, type);
        }
Пример #2
0
        internal static void HandleEmptyDirectories(XDocument doc)
        {
            XElement product = doc.Root.Select("Product");

            var dummyDirs = product.Descendants("Directory")
                            .SelectMany(x => x.Elements("Component"))
                            .Where(e => e.HasAttribute("Id", v => v.EndsWith(".EmptyDirectory")))
                            .Select(x => x.Parent("Directory")).ToArray();

            if (SupportEmptyDirectories == CompilerSupportState.Automatic)
            {
                SupportEmptyDirectories = dummyDirs.Any() ? CompilerSupportState.Enabled : CompilerSupportState.Disabled; //it wasn't set by user so set it if any empty dir is detected
                Compiler.OutputWriteLine("Wix# support for EmptyDirectories is automatically " + SupportEmptyDirectories.ToString().ToLower());
            }

            if (SupportEmptyDirectories == CompilerSupportState.Enabled)
            {
                if (dummyDirs.Any())
                {
                    foreach (var item in dummyDirs)
                    {
                        InsertEmptyComponentsInParentDirectories(doc, item);
                    }
                }

                foreach (XElement xDir in product.Descendants("Directory").ToArray())
                {
                    var dirComponents = xDir.Elements("Component");

                    if (dirComponents.Any())
                    {
                        var componentsWithNoFiles = dirComponents.Where(x => !x.ContainsFiles()).ToArray();

                        //'EMPTY DIRECTORY' support processing section
                        foreach (XElement item in componentsWithNoFiles)
                        {
                            // Ridiculous MSI constraints:
                            //  * you cannot install empty folders
                            //    - workaround is to insert empty component with CreateFolder element
                            //  * if Component+CreateFolder element is inserted the folder will not be removed on uninstall
                            //    - workaround is to insert RemoveFolder element in to empty component as well
                            //  * if Component+CreateFolder+RemoveFolder elements are placed in a dummy component to handle an empty folder
                            //    any parent folder with no files/components will not be removed on uninstall.
                            //    - workaround is to insert Component+Create+RemoveFolder elements in any parent folder with no files.
                            //
                            // OMG!!!! If it is not over-engineering I don't know what is.

                            bool oldAlgorithm = false;

                            if (!oldAlgorithm)
                            {
                                //current approach
                                InsertCreateFolder(item);
                                if (!xDir.ContainsAnyRemoveFolder())
                                {
                                    InsertRemoveFolder(xDir, item, "uninstall");
                                }
                            }
                            else
                            {
                                //old approach
                                if (!item.Attribute("Id").Value.EndsWith(".EmptyDirectory"))
                                {
                                    InsertCreateFolder(item);
                                }
                                else if (!xDir.ContainsAnyRemoveFolder())
                                {
                                    InsertRemoveFolder(xDir, item, "uninstall"); //to keep WiX/compiler happy and allow removal of the dummy directory
                                }
                            }
                        }
                    }
                }
            }
        }