Skip to content

Resolve features from @(ReferencePath) after ResolveAssemblyReferences#531

Merged
SimonCropp merged 1 commit intomainfrom
Resolve-features-from-@(ReferencePath)-after-ResolveAssemblyReferences
Apr 10, 2026
Merged

Resolve features from @(ReferencePath) after ResolveAssemblyReferences#531
SimonCropp merged 1 commit intomainfrom
Resolve-features-from-@(ReferencePath)-after-ResolveAssemblyReferences

Conversation

@SimonCropp
Copy link
Copy Markdown
Owner

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.

 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.
@SimonCropp SimonCropp added this to the 10.2.0 milestone Apr 10, 2026
@SimonCropp SimonCropp merged commit 5cf00af into main Apr 10, 2026
6 checks passed
@SimonCropp SimonCropp deleted the Resolve-features-from-@(ReferencePath)-after-ResolveAssemblyReferences branch April 10, 2026 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant