예제 #1
0
        /// <summary>
        /// Initializes a new VersionUpdater instance.
        /// </summary>
        /// <param name="input">
        /// The input string containing the AssemblyVersion attribute
        /// to update.
        /// </param>
        /// <param name="options">The options to use for updating the version number.</param>
        public VersionUpdater(string input, Options options)
        {
            // Save the input
            this._Input  = input;
            this._Output = input;

            if (VersionType.Assembly == options.VersionType)
            {
                this._ActiveRegex   = AssemblyVersionRegex;
                this._ReplaceFormat = "AssemblyVersion(\"{0}\")";
            }
            else
            {
                this._ActiveRegex   = FileVersionRegex;
                this._ReplaceFormat = "AssemblyFileVersion(\"{0}\")";
            }

            try
            {
                Match match = this._ActiveRegex.Match(input);

                if (null != match)
                {
                    string inputVersion = match.Groups["version"].Value;

                    if (null != inputVersion && string.Empty != inputVersion)
                    {
                        // We found an AssemblyVersion in the input string so let's update it.
                        VersionCalculator calculator = new VersionCalculator(inputVersion);

                        calculator.StartDate          = options.StartDate;
                        calculator.BuildNumberType    = options.BuildNumberType;
                        calculator.RevisionNumberType = options.RevisionNumberType;

                        string replacement = string.Format(this._ReplaceFormat, calculator.NewVersion.ToString());

                        string outputVersion = this._ActiveRegex.Replace(input, replacement, 1);
                        this._Output = outputVersion;
                    }
                    else
                    {
                        // There was no Version in the input string. Warn the user
                        // and set the output string to the input string.
                        Console.Error.WriteLine("Version not found in input. Output equals input.");
                        this._Output = input;
                    }
                }
            }
            catch (Exception)
            {
                // There was a problem finding or updating the version number.
                this._Output = input;
                throw;
            }
        }
예제 #2
0
        private void doUpdate(string inputVersion, Options options)
        {
            string replacement = "";

            if (options.ReplacementVersion != null)
            {
                replacement = string.Format(this._ReplaceFormat,
                                            options.ReplacementVersion);
            }
            else if (null == inputVersion || string.Empty == inputVersion)
            {
                VersionCalculator calculator = new VersionCalculator("1.0.0.0");

                calculator.StartDate          = options.StartDate;
                calculator.BuildNumberType    = options.BuildNumberType;
                calculator.RevisionNumberType = options.RevisionNumberType;

                string replacment = options.AttributeName + "(\"" + calculator.NewVersion.ToString() + "\")";

                this._Output = this._Input.Replace(options.AttributeName + "(\"1.0.*\")", replacment);
                return;
            }
            else
            {
                VersionCalculator calculator = new VersionCalculator(inputVersion);

                calculator.StartDate          = options.StartDate;
                calculator.BuildNumberType    = options.BuildNumberType;
                calculator.RevisionNumberType = options.RevisionNumberType;

                replacement = string.Format(this._ReplaceFormat,
                                            calculator.NewVersion.ToString());
            }

            string outputVersion = this._ActiveRegex.Replace(this._Input, replacement, 1);

            this._Output = outputVersion;
        }
예제 #3
0
        private void doUpdate(string inputVersion, Options options)
        {
            string replacement = "";
            if (options.ReplacementVersion != null)
            {
                replacement = string.Format(this._ReplaceFormat,
                    options.ReplacementVersion);
            }
            else if (null == inputVersion || string.Empty == inputVersion)
            {
                VersionCalculator calculator = new VersionCalculator("1.0.0.0");

                calculator.StartDate = options.StartDate;
                calculator.BuildNumberType = options.BuildNumberType;
                calculator.RevisionNumberType = options.RevisionNumberType;

                string replacment = options.AttributeName + "(\"" + calculator.NewVersion.ToString() + "\")";

                this._Output = this._Input.Replace(options.AttributeName + "(\"1.0.*\")", replacment);
                return;
            }
            else
            {
                VersionCalculator calculator = new VersionCalculator(inputVersion);

                calculator.StartDate = options.StartDate;
                calculator.BuildNumberType = options.BuildNumberType;
                calculator.RevisionNumberType = options.RevisionNumberType;

                replacement = string.Format(this._ReplaceFormat,
                    calculator.NewVersion.ToString());
            }

            string outputVersion = this._ActiveRegex.Replace(this._Input, replacement, 1);

            this._Output = outputVersion;
        }
예제 #4
0
        /// <summary>
        /// Initializes a new VersionUpdater instance.
        /// </summary>
        /// <param name="input">
        /// The input string containing the AssemblyVersion attribute
        /// to update.
        /// </param>
        /// <param name="options">The options to use for updating the version number.</param>
        public VersionUpdater(string input, Options options)
        {
            // Save the input
            this._Input = input;
            this._Output = input;

            if(VersionType.Assembly == options.VersionType)
            {
                this._ActiveRegex = AssemblyVersionRegex;
                this._ReplaceFormat = "AssemblyVersion(\"{0}\")";
            }
            else if (VersionType.File == options.VersionType)
            {
                this._ActiveRegex = FileVersionRegex;
                this._ReplaceFormat = "AssemblyFileVersion(\"{0}\")";
            }
            else
            {
                this._ActiveRegex = InformationalVersionRegex;
                this._ReplaceFormat = "AssemblyInformationalVersion(\"{0}\")";
            }

            try
            {
                Match match = this._ActiveRegex.Match(input);

                if(null != match)
                {
                    string inputVersion = match.Groups["version"].Value;

                    if (options.VersionIsPinned)
                    {
                        string replacement = string.Format(this._ReplaceFormat,
                            options.PinVersion);

                        string outputVersion = this._ActiveRegex.Replace(input, replacement, 1);
                        this._Output = outputVersion;
                    }
                    else if (null != inputVersion && string.Empty != inputVersion)
                    {
                        // We found an AssemblyVersion in the input string so let's update it.
                        VersionCalculator calculator = new VersionCalculator(inputVersion);

                        calculator.StartDate = options.StartDate;
                        calculator.BuildNumberType = options.BuildNumberType;
                        calculator.RevisionNumberType = options.RevisionNumberType;

                        string replacement = string.Format(this._ReplaceFormat,
                            calculator.NewVersion.ToString());

                        string outputVersion = this._ActiveRegex.Replace(input, replacement, 1);
                        this._Output = outputVersion;
                    }
                    else
                    {
                        // There was no Version in the input string. Warn the user
                        // and set the output string to the input string.
                        Console.Error.WriteLine("Version not found in input. " +
                            "Output equals input.");
                        this._Output = input;
                    }
                }

            }
            catch(Exception)
            {
                // There was a problem finding or updating the version number.
                this._Output = input;
                throw;
            }
        }