コード例 #1
0
        //=====================================================================
        // Methods

        /// <summary>
        /// Main program entry point
        /// </summary>
        /// <param name="args">The command line arguments.  This should be a
        /// list of projects to build and an optional "/v" option to provide
        /// verbose output.</param>
        /// <returns>Zero on success, non-zero on failure</returns>
        static int Main(string[] args)
        {
            DocumentAssembly docAsm;
            ContentItem      ci;
            DependencyItem   di;
            OptionInfo       lastOption = null;

            SandcastleProject        newProject = new SandcastleProject();
            List <OptionInfo>        options    = new List <OptionInfo>();
            List <SandcastleProject> projects   = new List <SandcastleProject>();
            bool success = false;

            char[] wildcards     = new char[] { '*', '?' };
            string currentFolder = Directory.GetCurrentDirectory();

            Assembly asm = Assembly.GetEntryAssembly();

            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);

            Console.WriteLine("{0}, version {1}\r\n{2}\r\nE-Mail: " +
                              "[email protected]\r\n", fvi.ProductName, fvi.ProductVersion,
                              fvi.LegalCopyright);

            try
            {
                // Get a list of options and expand any response files
                foreach (string option in args)
                {
                    if (option[0] == '@')
                    {
                        LoadResponseFile(option.Substring(1), options);
                    }
                    else
                    {
                        options.Add(new OptionInfo(option));
                    }
                }

                if (options.Count == 0)
                {
                    ShowHelp();
                    return(1);
                }

                // Build a list of projects and apply any properties to them
                // as needed.
                foreach (OptionInfo option in options)
                {
                    lastOption = option;

                    switch (option.Name)
                    {
                    case "help":
                    case "?":
                        ShowHelp();
                        break;

                    case "verbose":
                    case "v":
                        verbose = true;
                        break;

                    case "new":
                    case "project":
                        if (newProject.IsDirty || newProject.Filename !=
                            SandcastleProject.DefaultName)
                        {
                            projects.Add(newProject);
                        }

                        newProject = new SandcastleProject();

                        if (option.Name == "project")
                        {
                            newProject.LoadProject(option.Value);
                        }
                        break;

                    case "assembly":
                        if (option.Value.IndexOfAny(wildcards) == -1)
                        {
                            // Single assembly
                            docAsm = new DocumentAssembly();
                            docAsm.AssemblyPath = new FilePath(option.Value);

                            if (!String.IsNullOrEmpty(option.SecondValue))
                            {
                                docAsm.XmlCommentsPath =
                                    new FilePath(option.SecondValue);
                            }

                            newProject.Assemblies.Add(docAsm);
                        }
                        else
                        {
                            AddAssemblyWildCard(option.Value, newProject,
                                                false);
                        }
                        break;

                    case "comments":
                        if (option.Value.IndexOfAny(wildcards) == -1)
                        {
                            docAsm = new DocumentAssembly();
                            docAsm.XmlCommentsPath = new FilePath(option.Value);
                            docAsm.CommentsOnly    = true;

                            newProject.Assemblies.Add(docAsm);
                        }
                        else
                        {
                            AddAssemblyWildCard(option.Value, newProject,
                                                true);
                        }
                        break;

                    case "addcontent":
                        ci            = new ContentItem();
                        ci.SourcePath = new FilePath(option.Value);

                        if (!String.IsNullOrEmpty(option.SecondValue))
                        {
                            ci.DestinationPath = option.SecondValue;
                        }

                        newProject.AdditionalContent.Add(ci);

                        if (!String.IsNullOrEmpty(option.ThirdValue))
                        {
                            ci.ExcludeItems = Convert.ToBoolean(
                                option.ThirdValue, CultureInfo.InvariantCulture);
                        }
                        break;

                    case "dependency":
                        di = new DependencyItem();
                        di.DependencyPath = new FileFolderGacPath(
                            option.Value);

                        newProject.Dependencies.Add(di);
                        break;

                    case "component":
                        newProject.ComponentConfigurations.Add(
                            option.Value, option.SecondValue);
                        break;

                    default:
                        // Set a simple project property
                        newProject.SetProperty(option.Name, option.Value);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                if (lastOption != null)
                {
                    Console.WriteLine("Fatal error applying command line " +
                                      "option '{0}' in project '{1}': {2}",
                                      lastOption.OptionText, newProject.Filename,
                                      ex.ToString());
                }
                else
                {
                    Console.WriteLine("Unexpected error while parsing " +
                                      "command line options: {0}", ex.ToString());
                }

                return(2);
            }

            // Add the final project if necessary
            if (newProject.IsDirty || newProject.Filename !=
                SandcastleProject.DefaultName)
            {
                projects.Add(newProject);
            }

            // Build each of the projects
            foreach (SandcastleProject project in projects)
            {
                success = BuildProject(project);

                if (!success)
                {
                    break;
                }

                // Switch back to the original folder in case we are
                // building a default project next.
                Directory.SetCurrentDirectory(currentFolder);
            }

            return((success) ? 0 : 3);
        }