Example #1
0
        private string GetArgumentParameter(string[] args, int index, bool allowSpaces)
        {
            string truncatedCommandSwitch = args[index];
            string commandSwitchValue     = args[index + 1];

            //increment the index to the switch value
            index++;

            if (IsValidArg(args, index) && !String.IsNullOrEmpty(commandSwitchValue.Trim()))
            {
                if (!allowSpaces && commandSwitchValue.Contains(" "))
                {
                    this.Core.Messaging.Write(HarvesterErrors.SpacesNotAllowedInArgumentValue(truncatedCommandSwitch, commandSwitchValue));
                }
                else
                {
                    return(commandSwitchValue);
                }
            }
            else
            {
                this.Core.Messaging.Write(HarvesterErrors.ArgumentRequiresValue(truncatedCommandSwitch));
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Parse the command line options for this extension.
        /// </summary>
        /// <param name="type">The active harvester type.</param>
        /// <param name="args">The option arguments.</param>
        public override void ParseOptions(string type, string[] args)
        {
            if ("project" == type)
            {
                string[]     allOutputGroups  = VSProjectHarvester.GetOutputGroupNames();
                bool         suppressUniqueId = false;
                bool         generateWixVars  = false;
                bool         useToolsVersion  = false;
                GenerateType generateType     = GenerateType.Components;
                string       directoryIds     = null;
                string       msbuildBinPath   = null;
                string       projectName      = null;
                string       configuration    = null;
                string       platform         = null;
                ArrayList    outputGroups     = new ArrayList();

                for (int i = 0; i < args.Length; i++)
                {
                    if ("-configuration" == args[i])
                    {
                        configuration = args[++i];
                    }
                    else if ("-directoryid" == args[i])
                    {
                        if (!IsValidArg(args, ++i))
                        {
                            throw new WixException(HarvesterErrors.InvalidDirectoryId(args[i]));
                        }

                        directoryIds = args[i];
                    }
                    else if ("-generate" == args[i])
                    {
                        if (!IsValidArg(args, ++i))
                        {
                            throw new WixException(HarvesterErrors.InvalidProjectOutputType(args[i]));
                        }

                        string genType = args[i].ToUpperInvariant();
                        switch (genType)
                        {
                        case "CONTAINER":
                            generateType = GenerateType.Container;
                            break;

                        case "COMPONENTS":
                            generateType = GenerateType.Components;
                            break;

                        case "PACKAGEGROUP":
                            generateType = GenerateType.PackageGroup;
                            break;

                        case "PAYLOADGROUP":
                            generateType = GenerateType.PayloadGroup;
                            break;

                        default:
                            throw new WixException(HarvesterErrors.InvalidProjectOutputType(genType));
                        }
                    }
                    else if ("-msbuildbinpath" == args[i])
                    {
                        if (!IsValidArg(args, ++i))
                        {
                            throw new WixException(HarvesterErrors.ArgumentRequiresValue(args[i - 1]));
                        }

                        msbuildBinPath = args[i];
                    }
                    else if ("-platform" == args[i])
                    {
                        platform = args[++i];
                    }
                    else if ("-pog" == args[i])
                    {
                        if (!IsValidArg(args, ++i))
                        {
                            throw new WixException(HarvesterErrors.InvalidOutputGroup(args[i]));
                        }

                        string pogName = args[i];
                        bool   found   = false;
                        foreach (string availableOutputGroup in allOutputGroups)
                        {
                            if (String.Equals(pogName, availableOutputGroup, StringComparison.Ordinal))
                            {
                                outputGroups.Add(availableOutputGroup);
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            throw new WixException(HarvesterErrors.InvalidOutputGroup(pogName));
                        }
                    }
                    else if (args[i].StartsWith("-pog:", StringComparison.Ordinal))
                    {
                        this.Core.Messaging.Write(WarningMessages.DeprecatedCommandLineSwitch("pog:", "pog"));

                        string pogName = args[i].Substring(5);
                        bool   found   = false;
                        foreach (string availableOutputGroup in allOutputGroups)
                        {
                            if (String.Equals(pogName, availableOutputGroup, StringComparison.Ordinal))
                            {
                                outputGroups.Add(availableOutputGroup);
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            throw new WixException(HarvesterErrors.InvalidOutputGroup(pogName));
                        }
                    }
                    else if ("-projectname" == args[i])
                    {
                        if (!IsValidArg(args, ++i))
                        {
                            throw new WixException(HarvesterErrors.InvalidProjectName(args[i]));
                        }

                        projectName = args[i];
                    }
                    else if ("-suid" == args[i])
                    {
                        suppressUniqueId = true;
                    }
                    else if ("-usetoolsversion" == args[i])
                    {
                        useToolsVersion = true;
                    }
                    else if ("-wixvar" == args[i])
                    {
                        generateWixVars = true;
                    }
                }

                if (outputGroups.Count == 0)
                {
                    throw new WixException(HarvesterErrors.NoOutputGroupSpecified());
                }

                VSProjectHarvester harvester = new VSProjectHarvester(
                    (string[])outputGroups.ToArray(typeof(string)));

                harvester.SetUniqueIdentifiers = !suppressUniqueId;
                harvester.GenerateWixVars      = generateWixVars;
                harvester.GenerateType         = generateType;
                harvester.DirectoryIds         = directoryIds;
                harvester.MsbuildBinPath       = msbuildBinPath;
                harvester.ProjectName          = projectName;
                harvester.Configuration        = configuration;
                harvester.Platform             = platform;
                harvester.UseToolsVersion      = String.IsNullOrEmpty(msbuildBinPath) || useToolsVersion;

                this.Core.Harvester.Extension = harvester;
            }
        }