Example #1
0
        /// <summary>
        /// Builds the WiX source file (*.wxs) from the specified <see cref="Project"/> instance.
        /// </summary>
        /// <param name="project">The <see cref="Project"/> instance.</param>
        /// <param name="path">The path to the WXS file to be build.</param>
        /// <param name="type">The type (<see cref="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 static string BuildWxs(Project project, string path, OutputType type)
        {
            //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;

            XDocument doc = GenerateWixProj(project);

            IndjectCustomUI(project.CustomUI, doc);
            DefaultWixSourceGeneratedHandler(doc);
            AutoElements.InjectAutoElementsHandler(doc);
            AutoElements.NormalizeFilePaths(doc, project.SourceBaseDir, EmitRelativePaths);

            if (type == OutputType.MSM)
            {
                //remove all pure MSI elements
                ConvertMsiToMsm(doc);
            }

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

            string xml = "";
            using (IO.StringWriter sw = new StringWriterWithEncoding(project.Encoding))
            {
                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(path, false, project.Encoding))
                sw.WriteLine(xml);

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

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

            return path;
        }
Example #2
0
        /// <summary>
        /// Builds the WiX source file (*.wxs) from the specified <see cref="Project"/> instance.
        /// </summary>
        /// <param name="project">The <see cref="Project"/> instance.</param>
        /// <param name="path">The path to the WXS file to be build.</param>
        /// <param name="type">The type (<see cref="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 static string BuildWxs(Project project, string path, OutputType type)
        {
            //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;

            XDocument doc = GenerateWixProj(project);

            IndjectCustomUI(project.CustomUI, doc);
            DefaultWixSourceGeneratedHandler(doc);
            AutoElements.InjectAutoElementsHandler(doc);
            AutoElements.NormalizeFilePaths(doc, project.SourceBaseDir, EmitRelativePaths);

            if (type == OutputType.MSM)
            {
                //remove all pure MSI elements
                ConvertMsiToMsm(doc);
            }

            //issue#63 Inconsistent XML namespace usage in generated Wix source
            doc.AddDefaultNamespaces();

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

            doc.AddDefaultNamespaces();

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

            DefaultWixSourceFormatedHandler(ref xml);

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

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

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

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

            return path;
        }