Resolve features from @(ReferencePath) after ResolveAssemblyReferences#531
Merged
SimonCropp merged 1 commit intomainfrom Apr 10, 2026
Conversation
Feature detection now runs in a single PolyfillResolveFeatures target hooked AfterTargets="ResolveAssemblyReferences" BeforeTargets="CoreCompile", and inspects @(ReferencePath) — the final list of assemblies csc will see, with NuGetPackageId / NuGetPackageVersion preserved on NuGet-resolved items. Replaces the previous two-target arrangement (PreparePolyfill running early off @(ResolvedCompileFileDefinitions), plus a DetectBclMemoryPackageRef fallback off @(PackageReference)). The fallback was too optimistic: it fired whenever a PackageReference for Microsoft.Bcl.Memory existed, even when the dll was not actually in csc's /reference list (stale IDE state, ExcludeAssets="compile", etc.). The result was that RefsBclMemory got set, Polyfill's own Index/Range types were suppressed, and the BCL types were also missing — producing CS0246 in Polyfill_IEnumerable_ElementAt and Polyfill_IEnumerable_Take. Inspecting @(ReferencePath) post-RAR makes the feature flags reflect what csc will actually see, eliminating that whole class of bug. Adds ConsumeBclMemoryExcludeCompile as a regression test that uses ExcludeAssets="compile" to reproduce the failure mode without needing an IDE in the loop. ConsumeBclMemoryNoResolve loses its now-impossible PreparePolyfill override and stays as a plain smoke test. If you want it shorter, the body can collapse to: Single PolyfillResolveFeatures target runs after ResolveAssemblyReferences and inspects @(ReferencePath), so feature flags only fire when the corresponding assembly is actually in the reference list csc will see. Replaces the early PreparePolyfill + DetectBclMemoryPackageRef pair, whose @(PackageReference)-based fallback could set RefsBclMemory while the dll was missing from /reference (stale IDE state, ExcludeAssets="compile"), causing CS0246 in Polyfill_IEnumerable_ElementAt / Take. Adds ConsumeBclMemoryExcludeCompile as a regression test.
This was referenced Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature detection now runs in a single PolyfillResolveFeatures target
hooked AfterTargets="ResolveAssemblyReferences" BeforeTargets="CoreCompile",
and inspects @(ReferencePath) — the final list of assemblies csc will see,
with NuGetPackageId / NuGetPackageVersion preserved on NuGet-resolved items.
Replaces the previous two-target arrangement (PreparePolyfill running early
off @(ResolvedCompileFileDefinitions), plus a DetectBclMemoryPackageRef
fallback off @(PackageReference)). The fallback was too optimistic: it
fired whenever a PackageReference for Microsoft.Bcl.Memory existed, even
when the dll was not actually in csc's /reference list (stale IDE state,
ExcludeAssets="compile", etc.). The result was that RefsBclMemory got set,
Polyfill's own Index/Range types were suppressed, and the BCL types were
also missing — producing CS0246 in Polyfill_IEnumerable_ElementAt and
Polyfill_IEnumerable_Take.
Inspecting @(ReferencePath) post-RAR makes the feature flags reflect what
csc will actually see, eliminating that whole class of bug.
Adds ConsumeBclMemoryExcludeCompile as a regression test that uses
ExcludeAssets="compile" to reproduce the failure mode without needing an
IDE in the loop. ConsumeBclMemoryNoResolve loses its now-impossible
PreparePolyfill override and stays as a plain smoke test.
If you want it shorter, the body can collapse to:
Single PolyfillResolveFeatures target runs after ResolveAssemblyReferences
and inspects @(ReferencePath), so feature flags only fire when the
corresponding assembly is actually in the reference list csc will see.
Replaces the early PreparePolyfill + DetectBclMemoryPackageRef pair, whose
@(PackageReference)-based fallback could set RefsBclMemory while the dll
was missing from /reference (stale IDE state, ExcludeAssets="compile"),
causing CS0246 in Polyfill_IEnumerable_ElementAt / Take.
Adds ConsumeBclMemoryExcludeCompile as a regression test.