Skip to content

The Bundler API should allow for pre-computing the lists of included and excluded files in the bundle #124051

Closed

Description

@baronfel

Background and motivation

Bundle Generation in the .NET SDK uses the GenerateBundle Task to call the Bundler hosting APIs.

These APIs are great for one-shot bundle generation, but there's a bug in the SDK targets here around incrementality because of the side-effecting nature of these APIs. This was raised by a user in dotnet/sdk#52151, and it comes down to the fact that Bundle generation returns Items that weren't included as a side-effect, but when the Target is considered up to date no Tasks are run, so we don't know which files to copy that weren't part of the bundle.

To properly support incrementality, we need to be able to pre-compute the included/excluded files that would be in a given bundle given a set of inputs and associated bundling options. Knowing these lists lets us properly ensure that in all cases, files that are excluded from the bundle will be copied to the relevant output directory. We've done this manually in dotnet/sdk#52755 for now, but would love to use a direct API.

API Proposal

Something along the lines of

public class Bundler
{
  public BundleContents PrecomputeBundleContents(IReadOnlyList<FileSpec> fileSpecs);
}

public class BundleContents
{
  public IReadOnlyList<FileSpec> IncludedInBundle { get; }
  public IReadOnlyList<FileSpec> ExcludedFromBundle { get; }
}

would be enough. As a bonus, GenerateBundle might be able to have an overload that did zero filtering/validation if passed some kind of pre-validated input set.

API Usage

In our pre-compute Target, we'd have a MSBuild Task that would

  • create the Bundler instance
  • provide the full input file set to the new filtering method

Then, the 'PrepareFilesToBundle' step would

  • use the results of that input file set filtering to construct a pre-filtered list of inputs for proper bundling
  • use the results of that input file set filtering to ensure that non-bundled files are copied to the relevant output directory

And finally the actual bundle-generation Target would treat the list of actual bundle inputs as its incrementality inputs to tie everything all together nicely.

Alternative Designs

No response

Risks

No response

Activity

  1. added
    api-suggestion
    on Feb 5, 2026
  2. added
    untriaged
    on Feb 5, 2026
  3. added
    needs-area-label
    on Feb 5, 2026
  4. teo-tsirpanis commented on Feb 5, 2026

    @teo-tsirpanis
    Contributor

    These APIs are internal and not shipped to consumers; I don't think an API review would be needed here.

  5. removed
    needs-area-label
    on Feb 5, 2026
  6. dotnet-policy-service commented on Feb 5, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @jeffschwMSFT, @elinor-fung
    See info in area-owners.md if you want to be subscribed.

  7. removed
    api-suggestion
    on Mar 17, 2026
  8. changed the title [-][API Proposal]: The Bundler API should allow for pre-computing the lists of included and excluded files in the bundle[/-] [+]The Bundler API should allow for pre-computing the lists of included and excluded files in the bundle[/+] on Mar 17, 2026
  9. added this to the 11.0.0 milestone on Mar 31, 2026
  10. removed
    untriaged
    on Mar 31, 2026
  11. elinor-fung commented on Apr 29, 2026

    @elinor-fung
    Member

    @baronfel this is what I'm looking at adding. Does that work for you?

    namespace Microsoft.NET.HostModel.Bundle;
     
    public sealed class BundleContents
    {
        public FileSpec Host { get; }
        public IReadOnlyList<FileSpec> IncludedFiles { get; }
        public IReadOnlyList<FileSpec> ExcludedFiles { get; }
    }
     
    public class Bundler
    {
        // Compute which files would be included/excluded without generating a bundle
        // Throws if host binary is not in the fileSpecs
        public BundleContents ComputeBundleContents(IReadOnlyList<FileSpec> fileSpecs);
    
        // Generate a bundle from pre-computed bundle contents
        public string GenerateBundle(BundleContents bundleContents);
    }
  12. locked and limited conversation to collaborators on Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions