예제 #1
0
 private void AssertVersionModel(VersionModel model, string assemblyVersion, string fileVersion, string version, string nuGetPackageVersion, string nuGetFilename)
 {
     using (new AssertionScope())
     {
         model.AssemblyVersion.ToString().Should().Be(assemblyVersion);
         model.Version.Should().Be(version);
         model.FileVersion.ToString().Should().Be(fileVersion);
         model.NuGetPackageVersion.Should().Be(nuGetPackageVersion);
         model.NuGetFileName.Should().Be(nuGetFilename);
     }
 }
예제 #2
0
        public VersionModel ParseAppVersion(string appVersion)
        {
            AeroContext.Information($"VersionService.ParseAppVersion. Action: Start, AppVersion: {appVersion}");

            var model = new VersionModel();

            var match = new Regex(AppVersionRegEx).Match(appVersion);

            //Group 0 is the full match, 1-4 are the parts and 5 is the -preview
            if (!match.Success || match.Groups.Count < 4 || match.Groups.Count > 6)
            {
                AeroContext.Error($"VersionService.ParseAppVersion. Action: RegExFail, AppVersion: {appVersion}, GroupCount: {match.Groups?.Count}");
                throw new Exception("AppVersion RegEx Failed");
            }

            try
            {
                model.AssemblyVersion = new Version(
                    Convert.ToInt32(match.Groups[1].Value),
                    Convert.ToInt32(match.Groups[2].Value),
                    Convert.ToInt32(match.Groups[3].Value),
                    Convert.ToInt32(match.Groups[4].Value)
                    );
            }
            catch (Exception ex)
            {
                AeroContext.Error($"VersionService.ParseAppVersion. Action: VersionObjectCreationFailed, AppVersion: {appVersion}, {ex.ToLogString()}");
                throw;
            }

            //If we have a valid regex and we successfully created a version object then we can just set the Version to the appVersion and it will
            //work for either 1.2.3.4 or 1.2.3.4-preview
            model.Version = appVersion;

            if (match.Groups.Count == 6 && !string.IsNullOrWhiteSpace(match.Groups[5].Value))
            {
                var versionSuffix = $"{match.Groups[5]}.{model.AssemblyVersion.Revision}";
                model.NuGetPackageVersion = $"{model.AssemblyVersion.Major}.{model.AssemblyVersion.Minor}.{model.AssemblyVersion.Build}{versionSuffix}";
                //model.NuGetFileName = model.NuGetPackageVersion;
            }
            else
            {
                model.NuGetPackageVersion = $"{model.AssemblyVersion.Major}.{model.AssemblyVersion.Minor}.{model.AssemblyVersion.Build}+{model.AssemblyVersion.Revision}";
                //model.NuGetFileName = $"{model.AssemblyVersion.Major}.{model.AssemblyVersion.Minor}.{model.AssemblyVersion.Build}";
            }

            //With the release of one of the following, the fileName changed: .Net 6, VS2022, MSBUild 2022
            model.NuGetFileName = appVersion;

            AeroContext.Information($"VersionService.ParseAppVersion. Action: Stop, AppVersion: {appVersion}, {model.ToLogString()}");
            return(model);
        }