Skip to content

Fix interactive TFM selection to evaluate property references in file-based app TargetFrameworks#53206

Draft
Copilot wants to merge 3 commits intorelease/10.0.3xxfrom
copilot/fix-interactive-tfm-evaluation
Draft

Fix interactive TFM selection to evaluate property references in file-based app TargetFrameworks#53206
Copilot wants to merge 3 commits intorelease/10.0.3xxfrom
copilot/fix-interactive-tfm-evaluation

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

GetTargetFrameworksFromSourceFile was reading the raw TargetFrameworks directive value without expanding MSBuild property references, causing $(MyProperty) to appear as a literal framework name in the TFM selection UI/error output.

For example, this file-based app:

#:property TargetFramework=
#:property MyTfm=net9.0
#:property TargetFrameworks=$(MyTfm);net10.0
Console.WriteLine("Hello Multi-TFM");

Previously surfaced $(MyTfm) as a framework option instead of net9.0.

Changes

  • RunCommand.cs: Collect all #:property directives into a dictionary before evaluating TargetFrameworks, then expand $(PropertyName) references using a new ExpandMSBuildProperties helper. Last definition wins (matching MSBuild semantics). Circular references are resolved to empty string.
  • RunCommand.cs: Added [GeneratedRegex] for $(...) pattern matching (AOT-compatible); made RunCommand partial to support it.
  • RunFileTests.cs: Added regression test verifying that $(MyTfm) is evaluated to its property value in the TFM selection error output.
Original prompt

This section details on the original issue you should resolve

<issue_title>Interactive TFM selection doesn't evaluate TargetFrameworks extracted from file-based apps</issue_title>
<issue_description>The interactive TFM selection added in #51509 (cc @jonathanpeppers) extracts TargetFrameworks property without evaluating it and hence it won't work for files like the following:

#:property TargetFramework=
#:property MyTfm=net9.0
#:property TargetFrameworks=$(MyTfm);net10.0
Console.WriteLine("Hello Multi-TFM");

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

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.

2 participants