private static async Task <bool> BuildAndCollectErrorsAgainAndUpdateFile(
        ILogger logger,
        DirectoryInfo projectPath,
        int runNumber,
        FileInfo?buildFile,
        Dictionary <string, int> buildResult,
        Collection <AnalyzerProviderBaseRuleData> analyzerProviderBaseRules)
    {
        bool hasFoundNewErrors;

        try
        {
            var buildResultNextRun = await DotnetBuildHelper.BuildAndCollectErrors(
                logger,
                projectPath,
                runNumber,
                buildFile,
                useNugetRestore : true,
                useConfigurationReleaseMode : true,
                BuildDefaultTimeoutInSec,
                "     ");

            hasFoundNewErrors = buildResultNextRun.Count > 0;
            foreach (var(key, value) in buildResultNextRun)
            {
                if (buildResult.ContainsKey(key))
                {
                    buildResult[key] += value;
                }
                else
                {
                    buildResult.Add(key, value);
                }
            }
        }
        catch (DataException ex)
        {
            logger.LogError($"{EmojisConstants.Error} {ex.Message}");
            return(false);
        }

        if (hasFoundNewErrors)
        {
            var suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult);
            if (suppressionLinesPrAnalyzer.Any())
            {
                await EditorConfigHelper.UpdateRootFileRemoveCustomAtcAutogeneratedRuleSuppressions(projectPath);

                await EditorConfigHelper.UpdateRootFileAddCustomAtcAutogeneratedRuleSuppressions(projectPath, suppressionLinesPrAnalyzer);

                return(true);
            }
        }

        return(false);
    }
    private static async Task HandleTemporarySuppressions(
        ILogger logger,
        DirectoryInfo projectPath,
        FileInfo?buildFile,
        DirectoryInfo?temporarySuppressionsPath,
        bool temporarySuppressionAsExcel)
    {
        logger.LogInformation($"{AppEmojisConstants.AreaTemporarySuppression} Working on temporary suppressions");

        if (!FileHelper.ContainsSolutionOrProjectFile(projectPath) &&
            !FileHelper.IsSolutionOrProjectFile(buildFile))
        {
            logger.LogInformation("     Nothing to build! -projectPath do not contains a .sln or .csproj file");
            return;
        }

        var analyzerProviderBaseRules = await AnalyzerProviderBaseRulesHelper.GetAnalyzerProviderBaseRules(
            logger,
            ProviderCollectingMode.LocalCache,
            logWithAnsiConsoleMarkup : true);

        var stopwatch = Stopwatch.StartNew();

        logger.LogTrace("     Collecting build errors");
        var rootEditorConfigContent = string.Empty;

        if (temporarySuppressionsPath is null)
        {
            await EditorConfigHelper.UpdateRootFileRemoveCustomAtcAutogeneratedRuleSuppressions(projectPath);
        }
        else
        {
            rootEditorConfigContent = await EditorConfigHelper.ReadAllText(projectPath);

            DeleteSuppressionsFileInTempPath(temporarySuppressionsPath, temporarySuppressionAsExcel);
        }

        Dictionary <string, int> buildResult;

        try
        {
            buildResult = await DotnetBuildHelper.BuildAndCollectErrors(
                logger,
                projectPath,
                1,
                buildFile,
                useNugetRestore : true,
                useConfigurationReleaseMode : true,
                BuildDefaultTimeoutInSec,
                "     ");
        }
        catch (DataException ex)
        {
            logger.LogError($"{EmojisConstants.Error} {ex.Message}");
            return;
        }
        catch (IOException ex)
        {
            logger.LogError($"{EmojisConstants.Error} {ex.Message}");
            return;
        }

        if (buildResult.Any(x => x.Key.StartsWith("MSB", StringComparison.Ordinal)))
        {
            var errorTypes = buildResult
                             .Where(x => x.Key.StartsWith("MSB", StringComparison.Ordinal))
                             .Select(x => x.Key)
                             .OrderBy(x => x)
                             .ToList();

            logger.LogWarning($"     MSB-errors ({string.Join(',', errorTypes)}) was found, please correct them manually first and try again.");
        }
        else if (buildResult.Any(x => x.Key.StartsWith("NU", StringComparison.Ordinal)))
        {
            var errorTypes = buildResult
                             .Where(x => x.Key.StartsWith("NU", StringComparison.Ordinal))
                             .Select(x => x.Key)
                             .OrderBy(x => x)
                             .ToList();

            logger.LogWarning($"     NU-errors ({string.Join(',', errorTypes)}) was found, please correct them manually first and try again.");
        }
        else
        {
            var suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult);
            if (suppressionLinesPrAnalyzer.Any())
            {
                await EditorConfigHelper.UpdateRootFileAddCustomAtcAutogeneratedRuleSuppressions(projectPath, suppressionLinesPrAnalyzer);

                for (var i = 0; i < MaxNumberOfTimesToBuild; i++)
                {
                    var runAgain = await BuildAndCollectErrorsAgainAndUpdateFile(
                        logger,
                        projectPath,
                        2 + i,
                        buildFile,
                        buildResult,
                        analyzerProviderBaseRules);

                    if (!runAgain)
                    {
                        break;
                    }
                }

                suppressionLinesPrAnalyzer = GetSuppressionLines(analyzerProviderBaseRules, buildResult);
                if (temporarySuppressionsPath is not null)
                {
                    await EditorConfigHelper.WriteAllText(projectPath, rootEditorConfigContent);
                    await CreateSuppressionsFileInTempPath(logger, temporarySuppressionsPath, temporarySuppressionAsExcel, suppressionLinesPrAnalyzer);
                }
                else
                {
                    var totalSuppressions = suppressionLinesPrAnalyzer.Sum(x => x.Item2.Count);
                    logger.LogInformation($"{EmojisConstants.FileUpdated}   [yellow]/[/]{EditorConfigHelper.FileName} is updated with {totalSuppressions} suppressions");
                }
            }
            else
            {
                logger.LogTrace("     No suppressions to add.");
            }
        }

        stopwatch.Stop();
        logger.LogTrace($"     Collecting build errors time: {stopwatch.Elapsed.GetPrettyTime()}");
    }