public override bool Execute()
        {
            string[] dotSplit = PackageVersion.Split('.');
            MajorMinorVersion = dotSplit[0] + "." + dotSplit[1];

            string[] prereleaseSplit = PackageVersion.Split(new[] { '-' }, count: 2);
            MajorMinorPatchVersion = prereleaseSplit[0];
            VersionWithTilde       = MajorMinorPatchVersion;

            if (prereleaseSplit.Length > 1)
            {
                VersionWithTilde += "~" + prereleaseSplit[1];
            }

            return(true);
        }
コード例 #2
0
        private void SetVersion()
        {
            if (CommandLineSettings.SelectedVersion != InternalVersionSelectorE.Unknown)
            {
                switch (CommandLineSettings.SelectedVersion)
                {
                case InternalVersionSelectorE.AssemblyFileVersion:
                {
                    PackageVersion = FrameworkInformation.AssemblyFileVersion;
                    break;
                }

                case InternalVersionSelectorE.AssemblyVersion:
                {
                    PackageVersion = FrameworkInformation.AssemblyVersion;
                    break;
                }

                case InternalVersionSelectorE.PackageVersion:
                {
                    PackageVersion = FrameworkInformation.PackageVersion;
                    break;
                }

                default:
                {
                    PackageVersion = FrameworkInformation.AssemblyFileVersion;
                    break;
                }
                }
            }
            else
            {
                PackageVersion =
                    _HandleConfiguration.AppSettingsValues.ForceVersionOverride
                                                ? _HandleConfiguration.AppSettingsValues.VersionOverride
                                                : FrameworkInformation.PackageVersion;
            }
            if (String.IsNullOrWhiteSpace(PackageVersion))
            {
                PackageVersion = DEFAULT_VERSION;
            }
            string[] vPieces =
                PackageVersion.Split(DOT, StringSplitOptions.RemoveEmptyEntries);
            if (vPieces.Length != 4)
            {
                PackageVersion = DEFAULT_VERSION;
                vPieces        =
                    PackageVersion.Split(DOT, StringSplitOptions.RemoveEmptyEntries);
            }
            if (_HandleConfiguration.AppSettingsValues.UseDateBasedVersion)
            {
                DateTime vNow = DateTime.Now;
                vPieces[1]     = vNow.Year.ToString();
                vPieces[2]     = vNow.Date.ToString("Mdd");
                PackageVersion = $"{vPieces[0]}.{vPieces[1]}.{vPieces[2]}.{vPieces[3]}";
            }
            if (_HandleConfiguration.AppSettingsValues.AutoIncrementBuildNumber)
            {
                vPieces =
                    PackageVersion.Split(DOT, StringSplitOptions.RemoveEmptyEntries);
                if (short.TryParse(vPieces[3], out short vBuildNumber))
                {
                    vBuildNumber++;
                    vPieces[3]     = vBuildNumber.ToString();
                    PackageVersion =
                        $"{vPieces[0]}.{vPieces[1]}.{vPieces[2]}.{vPieces[3]}";
                    WriteVersionBackToProject(PackageVersion);
                }
            }
        }