Skip to content

dotnet reference add refuses a project whose TargetFramework is an alias (parses the alias text, not TargetFrameworkMoniker) #57317

In review

Description

@Nucs

Describe the bug

dotnet reference add (and dotnet add reference) refuses to reference a project whose TargetFramework is an alias, although restore, build and run accept the same ProjectReference when it is written by hand.

A TargetFramework alias is a TargetFramework value that is not a framework name, with the framework given by TargetFrameworkIdentifier and TargetFrameworkVersion. NuGet restore supports this: it reads each alias's TargetFrameworkMoniker. The CLI instead parses the TargetFramework text with NuGetFramework.Parse, gets an unsupported framework, and finds it incompatible with everything.

To Reproduce

Lib/Lib.csproj, an alias for netstandard2.0:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>portablelib</TargetFramework>
    <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
  </PropertyGroup>
</Project>

Lib/Answer.cs:

namespace Lib { public static class Answer { public static int Value => 42; } }

App/App.csproj, a net10.0 console app, with App/Program.cs: System.Console.WriteLine(Lib.Answer.Value);

> dotnet reference add Lib/Lib.csproj --project App/App.csproj
Project `...\Lib\Lib.csproj` cannot be added due to incompatible targeted frameworks between the two projects. Review the project you are trying to add and verify that is compatible with the following targets:
    - net10.0

Exit code 1. With the same line written by hand, <ProjectReference Include="../Lib/Lib.csproj" />, dotnet run --project App builds both projects and prints 42.

Measured with .NET SDK 11.0.100 and 10.0.101 on Windows x64.

Expected behavior

dotnet reference add accepts every reference that restore and build accept. For a TargetFramework (or TargetFrameworks entry) that is an alias, the compatibility check should use the framework NuGet uses: the inner evaluation's TargetFrameworkMoniker (and TargetPlatformMoniker), not the alias text.

Where

src/Cli/dotnet/Extensions/ProjectExtensions.cs, GetTargetFrameworks:

return uniqueTargetFrameworkStrings
    .Select((frameworkString) => NuGetFramework.Parse(frameworkString));

A fix could evaluate the project once per value with TargetFramework as a global property, then use NuGetFramework.ParseComponents(TargetFrameworkMoniker, TargetPlatformMoniker), as NuGet's restore does for aliases. It could do this only when NuGetFramework.Parse returns an unsupported framework, so that projects without aliases pay nothing.

Context

Aliases are how an MSBuild SDK gives its target frameworks names of its own. AsmFoundation.Sdk (assembly projects, .asmproj) names its two freestanding and libc, over .NETStandard 1.0 and 2.0. A C# project references such a project with an ordinary ProjectReference, and dotnet sln add handles it once the SDK sets DefaultProjectTypeGuid. dotnet reference add is the one command in that workflow that refuses it, so its users are told to write the ProjectReference line by hand instead.

Activity

  1. added
    untriaged
    on Nov 23, 2026
  2. locked and limited conversation to collaborators on Nov 23, 2026
  3. baronfel commented on Nov 23, 2026

    @baronfel
    Member

    Great report, and good analysis - this area of the CLI hasn't been updated to support TFM aliasing and it's very reasonable to expect it to work.

  4. added and removed
    untriaged
    on Nov 23, 2026
  5. added theissue type on Nov 23, 2026
  6. unlocked this conversation on Nov 23, 2026
  7. added
    cookie
    needs team triage
    on Nov 23, 2026
  8. github-actions commented on Nov 23, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    • 🏷️ Labels: Area-CLI Bug cookie Issue Monster Loves Cookies! needs team triage Requires a full team discussion
    • 💻 Assignment: none | @dotnet/dotnet-cli
    • 🟨 Confidence: medium - The CLI command is clear, but CODEOWNERS has no matching Area-CLI section, so routing defaults to the CLI team.

    ➡️ Summary: dotnet reference add rejects projects whose TargetFramework is an alias, parsing alias text instead of TargetFrameworkMoniker. Evaluate the project to get the moniker when NuGetFramework.Parse yields unsupported.

    Generated by 🏷️ Issue Triage for #57317 · copilot · auto (Claude Sonnet 5.5) · ~15 AIC · ⌖ ~2 AIC · ⊞ 15.5K · ◷

  9. Nucs commented on Nov 23, 2026

    @Nucs
    Author

    @baronfel Just for the record, I did not consent my Claude to create this issue 😂

  10. vurumalla92 commented on Nov 23, 2026

    @vurumalla92

    Hi @baronfel — thanks for confirming this area of the CLI has not been updated for TFM aliasing. Would a fix PR be welcome here? I would make dotnet reference add resolve the target framework through TargetFrameworkMoniker (as NuGet restore already does) instead of parsing the alias text. Happy to put it up if the team is open to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area-CLIBugcookieneeds team triage

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions