Preprocess() private method

private Preprocess ( ) : void
return void
Esempio n. 1
0
        /// <summary>
        /// Generates WiX XML source file the specified <see cref="Project"/> instance.
        /// </summary>
        /// <param name="project">The <see cref="Project"/> instance.</param>
        /// <returns>Instance of XDocument class representing in-memory WiX XML source file.</returns>
        public static XDocument GenerateWixProj(Project project)
        {
            project.Preprocess();

            ProjectValidator.Validate(project);

            project.ControlPanelInfo.AddMembersTo(project);

            project.AutoAssignedInstallDirPath = "";

            project.GenerateProductGuids();
            ResetCachedContent();

            string extraNamespaces = project.WixNamespaces.Distinct()
                                                          .Select(x => x.StartsWith("xmlns:") ? x : "xmlns:" + x)
                                                          .ConcatItems(" ");

            XDocument doc = XDocument.Parse(
                    @"<?xml version=""1.0"" encoding=""utf-8""?>
                         <Wix xmlns=""http://schemas.microsoft.com/wix/2006/wi"" " + extraNamespaces + @">
                            <Product>
                                <Package InstallerVersion=""200"" Compressed=""yes""/>
                                <Media Id=""1"" Cabinet=""" + (project as WixEntity).Id + @".cab"" EmbedCab=""yes"" />
                            </Product>
                        </Wix>");

            XElement product = doc.Root.Select("Product");
            product.Add(new XAttribute("Id", project.ProductId),
                         new XAttribute("Name", project.Name),
                         new XAttribute("Language", new CultureInfo(project.Language).LCID),
                         new XAttribute("Codepage", project.Codepage),
                         new XAttribute("Version", project.Version),
                         new XAttribute("UpgradeCode", project.UpgradeCode));

            if (project.ControlPanelInfo != null && project.ControlPanelInfo.Manufacturer.IsNotEmpty())
                product.SetAttribute("Manufacturer", project.ControlPanelInfo.Manufacturer);
            product.AddAttributes(project.Attributes);

            XElement package = product.Select("Package");

            package.SetAttribute("Description", project.Description)
                   .SetAttribute("Platform", project.Platform)
                   .SetAttribute("SummaryCodepage", project.Codepage)
                   .SetAttribute("Languages", new CultureInfo(project.Language).LCID)
                   .SetAttribute("InstallScope", project.InstallScope);

            if (project.EmitConsistentPackageId)
                package.CopyAttributeFrom(product, "Id");

            package.AddAttributes(project.Package.Attributes);

            product.Select("Media").AddAttributes(project.Media.Attributes);

            ProcessLaunchConditions(project, product);

            //extend wDir
            XElement dirs = product.AddElement(
                        new XElement("Directory",
                            new XAttribute("Id", "TARGETDIR"),
                            new XAttribute("Name", "SourceDir")));

            var featureComponents = new Dictionary<Feature, List<string>>(); //feature vs. component IDs
            var autoGeneratedComponents = new List<string>(); //component IDs
            var defaultFeatureComponents = new List<string>(); //default Feature (Complete setup) components

            ProcessDirectories(project, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirs);
            ProcessRegKeys(project, featureComponents, defaultFeatureComponents, product);
            ProcessEnvVars(project, featureComponents, defaultFeatureComponents, product);
            ProcessUsers(project, featureComponents, defaultFeatureComponents, product);
            ProcessSql(project, featureComponents, defaultFeatureComponents, product);
            ProcessCertificates(project, featureComponents, defaultFeatureComponents, product);
            ProcessProperties(project, product);
            ProcessCustomActions(project, product);
            ProcessBinaries(project, product); //it is important to call ProcessBinaries after all other ProcessX as they may insert some implicit "binaries"
            ProcessFeatures(project, product, featureComponents, autoGeneratedComponents, defaultFeatureComponents);

            //special properties
            if (project.UI != WUI.WixUI_ProgressOnly)
            {
                XElement installDir = GetTopLevelDir(product);

                //if UIRef is set to WIXUI_INSTALLDIR must also add
                //<Property Id="WIXUI_INSTALLDIR" Value="directory id" />
                if (project.UI == WUI.WixUI_InstallDir)
                    product.Add(new XElement("Property",
                                    new XAttribute("Id", "WIXUI_INSTALLDIR"),
                                    new XAttribute("Value", installDir.Attribute("Id").Value)));

                product.Add(new XElement("UIRef",
                                new XAttribute("Id", project.UI.ToString())));

                var extensionAssembly = Utils.PathCombine(WixLocation, @"WixUIExtension.dll");
                if (project.WixExtensions.Find(x => x == extensionAssembly) == null)
                    project.WixExtensions.Add(extensionAssembly);
            }

            if (project.EmbeddedUI != null)
            {
                string bynaryPath = project.EmbeddedUI.Name;
                if (project.EmbeddedUI is EmbeddedAssembly)
                {
                    var asmBin = project.EmbeddedUI as EmbeddedAssembly;

                    bynaryPath = asmBin.Name.PathChangeDirectory(project.OutDir.PathGetFullPath())
                                            .PathChangeExtension(".CA.dll");

                    var refAsms = asmBin.RefAssemblies.Add(typeof(Session).Assembly.Location)
                                                      .Concat(project.DefaultRefAssemblies)
                                                      .Distinct()
                                                      .ToArray();

                    PackageManagedAsm(asmBin.Name, bynaryPath, refAsms, project.OutDir, project.CustomActionConfig);
                }

                product.AddElement("UI")
                       .Add(new XElement("EmbeddedUI",
                                new XAttribute("Id", project.EmbeddedUI.Id),
                                new XAttribute("SourceFile", bynaryPath)));

                product.Select("UIRef").Remove();
            }

            if (!project.BannerImage.IsEmpty())
            {
                product.Add(new XElement("WixVariable",
                    new XAttribute("Id", "WixUIBannerBmp"),
                    new XAttribute("Value", Utils.PathCombine(project.SourceBaseDir, project.BannerImage))));
            }

            if (!project.BackgroundImage.IsEmpty())
            {
                product.Add(new XElement("WixVariable",
                    new XAttribute("Id", "WixUIDialogBmp"),
                    new XAttribute("Value", Utils.PathCombine(project.SourceBaseDir, project.BackgroundImage))));
            }

            if (!project.LicenceFile.IsEmpty())
            {
                if (!AllowNonRtfLicense && !project.LicenceFile.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
                    throw new ApplicationException("License file must have 'rtf' file extension. Specify 'Compiler.AllowNonRtfLicense=true' to overcome this constrain.");

                product.Add(
                       new XElement("WixVariable",
                       new XAttribute("Id", "WixUILicenseRtf"),
                       new XAttribute("Value", Utils.PathCombine(project.SourceBaseDir, project.LicenceFile)),
                       new XAttribute("xmlns", "")));
            }

            PostProcessMsm(project, product);
            ProcessUpgradeStrategy(project, product);

            return doc;
        }