src/MSBuild/Packaging/GitVersionCache/0/src/BuildTasks/BuildTaskExecutor.cs
/// <summary>
/// Gets the cached, or if not existing, the new calculated git version variables.
/// </summary>
/// <returns>If true the cache could be retrieved.</returns>
Gets the cached, or if not existing, the new calculated git version variables.
Gets the cached or if not existing the new calculated git version variables .
public bool LoadCacheOrGetVersion(GetVersionCacheTask buildTask)
        {
            using var fileLock = lockFile();
            string serializedGitVariables;
            bool isCache;
            if (!File.Exists(CacheFile)) {
                var gitDirectory = ParentOfGitDirectoryInfo.FullName.Replace("\\", "/");
                var configFile = GitVersionYamlFileInfo.FullName.Replace("\\", "/");
                var arguments = $"{gitDirectory} /config {configFile}";
                try {
                    var gitVersionProcessStartInfo = new GitVersionProcessStartInfo(args: arguments);
                    serializedGitVariables = SimpleProcess.StartAndWaitForExitButReadOutput(gitVersionProcessStartInfo);
                    isCache = false;
                } catch (Diagnostics.NonZeroExitCodeException error) {
                    var errorMessage = error.Message + $"(arguments: {arguments})" +
                        (error.InnerException is Exception ? " " + error.InnerException.Message : null);
                    throw new NonZeroExitCodeException(error.ExitCode, errorMessage);
                }
            } else {
                using var file = File.Open(CacheFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                using var fileReader = new StreamReader(file, Encoding.UTF8);
                serializedGitVariables = fileReader.ReadToEnd();
                isCache = true;
            }
            var jsonSerializerOptions = new JsonSerializerOptions();
            jsonSerializerOptions.Converters.Add(new NumberStringificationJsonConverter());
            var getVersionData = (GetVersionCacheTask)JsonSerializer.Deserialize(serializedGitVariables, typeof(GetVersionCacheTask), options: jsonSerializerOptions);
            var getVersionProperties = typeof(GetVersionCacheTask).GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
            foreach (var getVersionProperty in getVersionProperties) {
                var value = getVersionProperty.GetValue(getVersionData);
                if (value is null) {
                    continue;
                }
                getVersionProperty.SetValue(buildTask, value);
            }
            return isCache;
        }
public bool LoadCacheOrGetVersion ( GetVersionCacheTask buildTask ) { using var fileLock = lockFile ( ) ; string serializedGitVariables ; bool isCache ; if ( ! File . Exists ( CacheFile ) ) { var gitDirectory = ParentOfGitDirectoryInfo . FullName . Replace ( " \\ " , " " ) ; var configFile = GitVersionYamlFileInfo . FullName . Replace ( " \\ " , " " ) ; var arguments = $" { gitDirectory }  /config  { configFile } " ; try { var gitVersionProcessStartInfo = new GitVersionProcessStartInfo ( args : arguments ) ; serializedGitVariables = SimpleProcess . StartAndWaitForExitButReadOutput ( gitVersionProcessStartInfo ) ; isCache = false ; } catch ( Diagnostics . NonZeroExitCodeException error ) { var errorMessage = error . Message + $" (arguments:  { arguments } ) " + ( error . InnerException is Exception ? " " + error . InnerException . Message : null ) ; throw new NonZeroExitCodeException ( error . ExitCode , errorMessage ) ; } } else { using var file = File . Open ( CacheFile , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) ; using var fileReader = new StreamReader ( file , Encoding . UTF8 ) ; serializedGitVariables = fileReader . ReadToEnd ( ) ; isCache = true ; } var jsonSerializerOptions = new JsonSerializerOptions ( ) ; jsonSerializerOptions . Converters . Add ( new NumberStringificationJsonConverter ( ) ) ; var getVersionData = ( GetVersionCacheTask ) JsonSerializer . Deserialize ( serializedGitVariables , typeof ( GetVersionCacheTask ) , options : jsonSerializerOptions ) ; var getVersionProperties = typeof ( GetVersionCacheTask ) . GetProperties ( BindingFlags . Instance | BindingFlags . DeclaredOnly | BindingFlags . Public ) ; foreach ( var getVersionProperty in getVersionProperties ) { var value = getVersionProperty . GetValue ( getVersionData ) ; if ( value is null ) { continue ; } getVersionProperty . SetValue ( buildTask , value ) ; } return isCache ; }
Gets the cached, or if not existing, the new calculated git version variables.
Gets the cached or if not existing the new calculated git version variables .
If true the cache could be retrieved.
If true the cache could be retrieved .
buildTask
GetVersionCacheTask