Skip to content

Allow a custom file reader for the source files when generating a report #790

Closed

Description

@jeremy-morren

Use case

The Azure Pipelines coverage publisher (microsoft/azure-pipelines-coveragepublisher, used by PublishCodeCoverageResults@2) uses ReportGenerator. Before generating the report, it checks that each source file is inside the build's trusted directories.

To render the text it checked, I had to use internal members via reflection: CodeFile.additionalFileReader and AltCoverEmbeddedFileReader (microsoft/azure-pipelines-coveragepublisher#115, microsoft/azure-pipelines-coveragepublisher#116).

Suggestion

  1. Make IFileReader public
  2. Add an overload of Generator.GenerateReport that takes the parser result and an IFileReader:
public void GenerateReport(
    IReportConfiguration reportConfiguration,
    Settings settings,
    MinimumCoverageThresholds minimumCoverageThresholds,
    RiskHotspotsAnalysisThresholds riskHotspotsAnalysisThresholds,
    ParserResult parserResult,
    IFileReader fileReader)

Activity

  1. danielpalme commented on Oct 27, 2026

    @danielpalme
    Owner

    Release 5.5.12 which includes your PR is now available.

  2. jeremy-morren commented on Oct 27, 2026

    @jeremy-morren
    Author

    Thank you. This project is amazing, thank you very much.

  3. danielpalme commented on Nov 10, 2026

    @danielpalme
    Owner

    @jeremy-morren
    I just released version 5.6.0 which adds a new method to the IFileReader interface.

    See my main implementation for reference:

    public string[] LoadFile(string path, out string mappedPath, out string error)
    {
    mappedPath = this.MapPath(path);
    try
    {
    if (!File.Exists(mappedPath))
    {
    error = string.Format(CultureInfo.InvariantCulture, Resources.FileDoesNotExist, path);
    return null;
    }
    string[] lines = this.ReadAllLinesPreserveTrailingEmpty(mappedPath);
    error = null;
    return lines;
    }
    catch (Exception ex)
    {
    error = string.Format(CultureInfo.InvariantCulture, Resources.ErrorDuringReadingFile, path, ex.GetExceptionMessageForDisplay());
    return null;
    }
    }
    /// <summary>
    /// Loads the file with the given path.
    /// </summary>
    /// <param name="path">The path.</param>
    /// <param name="error">Error message if file reading failed, otherwise <code>null</code>.</param>
    /// <returns><code>null</code> if an error occurs, otherwise the lines of the file.</returns>
    public string[] LoadFile(string path, out string error)
    {
    return this.LoadFile(path, out _, out error);
    }

  4. jeremy-morren commented on Nov 11, 2026

    @jeremy-morren
    Author

    Thanks, update the Azure Pipelines coverage PR to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions