Click here to Skip to main content
15,892,809 members
Articles / Web Development / ASP.NET

A WIX web setup

Rate me:
Please Sign up or sign in to vote.
2.05/5 (8 votes)
9 May 20074 min read 71.9K   856   26  
Create WIX web setup using VS2005 and Wix 3.0
#region Using directives
using System;
using System.Collections.Generic;
using System.Text; 
#endregion

namespace Djans.ComponentWriter
{
    /// <summary>
    /// Starts the ComponentWriter from command line
    /// </summary>
    class Program
    {
        public static void Main(string[] args)
        {
            // Invalid no of arguments
            if (args.Length == 0)
            {                
                DisplayHelp();
                return;
            }

            // Help
            if ((args.Length == 1)
                && ((args[0] == "/?") 
                || (args[0] == "?") 
                || (args[0] == "-?")
                || (args[0] == "help")))
            {
                DisplayHelp();
                return;
            }

            // Invalid no of arguments
            if (args.Length != 3)
            {
                Console.WriteLine(string.Format("Error: Invalid no of arguments given."));
                DisplayHelp();
                return;
            }

            try
            {
                // Get the config from the command line
                ComponentWriterConfig config = new ComponentWriterConfig();
                config.SourceDirectory = args[0];
                config.OutputFile = args[1];
                config.UgradeFile = args[2];

                // Do the actual writing
                ComponentWriter componentWriter = new ComponentWriter();
                if (componentWriter.Write(config))
                {
                    Console.WriteLine("Files written successfully.");
                }
                else
                {
                    Console.WriteLine("Error: Could not write file. ComponentWriter Failed.");
                }
            }
            catch 
            {
                Console.WriteLine(string.Format("Error: Improper arguments given."));
                DisplayHelp();
                return;
            }
        }

        /// <summary>
        /// Displays Help
        /// </summary>
        private static void DisplayHelp()
        {
            StringBuilder help = new StringBuilder();
            help.AppendLine(Environment.NewLine + "-- HELP --");
            help.AppendLine(Environment.NewLine + "Description: Writes the files list from the given source directory in WIX format and upgrades the version number.");
            help.AppendLine(Environment.NewLine + "Switches: '?', '/?', '-?', 'help' diplays this help.");
            help.AppendLine("\t '-skip' skips updating the upgrade code.");
            help.AppendLine(Environment.NewLine + "Usage: \n ComponentWriter.exe [SourceDirectory] [OutputFile] [UgradeFile]");
            help.AppendLine("[SourceDirectory]: (Mandatory) The complete physical path of the directory where source files are stored.");
            help.AppendLine("                   The source files are those files which will be used for deployment.");
            help.AppendLine("[OutputFile]: (Mandatory) The wix file which lists out the directory structure, the files to be deployed and the feature element.");
            help.AppendLine("[UgradeFile]: (Optional) The wix file which has the upgrade element.");
            help.AppendLine("\t      To skip using upgrade, instead of the file name, provide '-skip' as the argument.");
            help.AppendLine(Environment.NewLine + "Example:");
            help.AppendLine("Write component file and upgrade the version: ");
            help.AppendLine(@"    Djans.ComponentWriter.exe c:\Project\Source c:\Project\WixSetup\Component.wxs c:\Project\WixSetup\WixMain.wxs");
            help.AppendLine("Write component file and do not upgrade the version: ");
            help.AppendLine(@"    Djans.ComponentWriter.exe c:\Project\Source c:\Project\WixSetup\Component.wxs -skip");
            help.AppendLine(Environment.NewLine + "Note: [UgradeFile] updates only first 3 parts, the 4th part is always 0 in the 4 part versioning.");
            Console.WriteLine(help.ToString());
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions