ToXml() public method

Emits WiX XML.
public ToXml ( ) : XContainer[]
return XContainer[]
Ejemplo n.º 1
0
        public void Should_Process_XmlAttribute()
        {
            var bootstrapper = new Bundle("test_name")
            {
                AboutUrl = "a_url",
                DisableRollback = false,
                IconFile = "icon.ico",
                Version = new Version("1.2.3.4"),
                UpgradeCode = new Guid("00000000-0000-0000-0000-000000000007")
            };

            var xml = bootstrapper.ToXml().Cast<XElement>().First();

            //<Bundle Name="test_name" DisableRollback="no" AboutUrl="a_url" IconSourceFile="icon.ico" UpgradeCode="00000000-0000-0000-0000-000000000007" Version="1.2.3.4" />
            Assert.Equal(6, xml.Attributes().Count());

            Assert.Equal("test_name", xml.ReadAttribute("Name"));
            Assert.Equal("a_url", xml.ReadAttribute("AboutUrl"));
            Assert.Equal("no", xml.ReadAttribute("DisableRollback"));
            Assert.Equal("icon.ico", xml.ReadAttribute("IconSourceFile"));
            Assert.Equal("1.2.3.4", xml.ReadAttribute("Version"));
            Assert.Equal("00000000-0000-0000-0000-000000000007", xml.ReadAttribute("UpgradeCode"));

            Assert.Null(xml.ReadAttribute("DisableSystemRestore")); //bool?
            Assert.Null(xml.ReadAttribute("Copyright"));//string
        }
Ejemplo n.º 2
0
        public void Should_Produce_BundleXml()
        {
            var bootstrapper =
                new Bundle("My Product",
                    new PackageGroupRef("NetFx40Web"),
                    new ExePackage(@"Samples\Setup1.exe")
                    {
                        Payloads = new[] { @"Samples\setup1.dll" },
                        InstallCommand = "/q /norestart",
                        PerMachine = true
                    },
                    new MsiPackage(@"Samples\SetupB.msi") { Vital = false },
                    new RollbackBoundary(),
                    new MsiPackage(@"Samples\SetupA.msi"));

            bootstrapper.AboutUrl = "https://wixsharp.codeplex.com/";
            bootstrapper.IconFile = "icon.ico";
            bootstrapper.Version = new Version("1.0.0.0");
            bootstrapper.UpgradeCode = new Guid("00000000-0000-0000-0000-000000000007");
            bootstrapper.Application.LicensePath = "readme.rtf";
            bootstrapper.Application.LocalizationFile = "en-us.wxl";
            bootstrapper.Application.LogoFile = "app_logo.png";

            var xml = bootstrapper.ToXml().First().ToString();

            var expected = @"<Bundle Name=""My Product"" AboutUrl=""https://wixsharp.codeplex.com/"" IconSourceFile=""icon.ico"" UpgradeCode=""00000000-0000-0000-0000-000000000007"" Version=""1.0.0.0"">
              <BootstrapperApplicationRef Id=""WixStandardBootstrapperApplication.RtfLicense"">
            <WixStandardBootstrapperApplication LogoFile=""app_logo.png"" LocalizationFile=""en-us.wxl"" LicenseFile=""readme.rtf"" xmlns=""http://schemas.microsoft.com/wix/BalExtension"" />
              </BootstrapperApplicationRef>
              <Chain>
            <PackageGroupRef Id=""NetFx40Web"" />
            <ExePackage InstallCommand=""/q /norestart"" SourceFile=""Samples\Setup1.exe"" PerMachine=""yes"">
              <Payload SourceFile=""Samples\setup1.dll"" />
            </ExePackage>
            <MsiPackage SourceFile=""Samples\SetupB.msi"" Vital=""no"" />
            <RollbackBoundary />
            <MsiPackage SourceFile=""Samples\SetupA.msi"" />
              </Chain>
            </Bundle>";
            Assert.Equal(expected, xml);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds the WiX source file (*.wxs) from the specified <see cref="Bundle"/> instance.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <returns></returns>
        public static string BuildWxs(Bundle project)
        {
            lock (typeof(Compiler))
            {
                //very important to keep "ClientAssembly = " in all "public Build*" methods to ensure GetCallingAssembly
                //returns the build script assembly but not just another method of Compiler.
                if (ClientAssembly.IsEmpty())
                    ClientAssembly = System.Reflection.Assembly.GetCallingAssembly().Location;

                WixEntity.ResetIdGenerator();
                string file = IO.Path.GetFullPath(IO.Path.Combine(project.OutDir, project.OutFileName) + ".wxs");

                if (IO.File.Exists(file))
                    IO.File.Delete(file);

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

                var doc = XDocument.Parse(
                  @"<?xml version=""1.0"" encoding=""utf-8""?>
                         <Wix xmlns=""http://schemas.microsoft.com/wix/2006/wi"" " + extraNamespaces + @">
                        </Wix>");

                doc.Root.Add(project.ToXml());

                AutoElements.NormalizeFilePaths(doc, project.SourceBaseDir, EmitRelativePaths);

                project.InvokeWixSourceGenerated(doc);
                if (WixSourceGenerated != null)
                    WixSourceGenerated(doc);

                string xml = "";
                using (IO.StringWriter sw = new StringWriterWithEncoding(Encoding.Default))
                {
                    doc.Save(sw, SaveOptions.None);
                    xml = sw.ToString();
                }

                //of course you can use XmlTextWriter.WriteRaw but this is just a temporary quick'n'dirty solution
                //http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2657663&SiteID=1
                xml = xml.Replace("xmlns=\"\"", "");

                DefaultWixSourceFormatedHandler(ref xml);

                project.InvokeWixSourceFormated(ref xml);
                if (WixSourceFormated != null)
                    WixSourceFormated(ref xml);

                using (var sw = new IO.StreamWriter(file, false, Encoding.Default))
                    sw.WriteLine(xml);

                Console.WriteLine("\n----------------------------------------------------------\n");
                Console.WriteLine("Wix project file has been built: " + file + "\n");

                project.InvokeWixSourceSaved(file);
                if (WixSourceSaved != null)
                    WixSourceSaved(file);

                return file;
            }
        }
Ejemplo n.º 4
0
        public void Should_Resolve_NoLicenseType()
        {
            var bootstrapper = new Bundle("My Product");

            bootstrapper.UpgradeCode = new Guid("00000000-0000-0000-0000-000000000007");
            bootstrapper.Application.LicensePath = null;

            var xml = bootstrapper.ToXml().First().ToString();

            var expected = @"<Bundle Name=""My Product"" UpgradeCode=""00000000-0000-0000-0000-000000000007"">
  <BootstrapperApplicationRef Id=""WixStandardBootstrapperApplication.HyperlinkLicense"">
    <WixStandardBootstrapperApplication LicenseUrl="""" xmlns=""http://schemas.microsoft.com/wix/BalExtension"" />
  </BootstrapperApplicationRef>
  <Chain />
</Bundle>";
            Assert.Equal(expected, xml);
        }