Skip to content

TargetFramework set in Directory.Build.props is silently wiped by Sdk.props, so only a csproj-body setting takes effect (readiness spec's deferred "own change") #100

Open

Description

@matt-edmondson

What's wrong

Sdk/Sdk.props:556 clears TargetFramework unconditionally:

<TargetFramework></TargetFramework>
<TargetFramework Condition="$(IsTestProject) == 'true'">net10.0</TargetFramework>

Directory.Build.props is imported by Microsoft.Common.props (via Microsoft.NET.Sdk's props) before ktsu.Sdk's Sdk.props runs. So a repository that writes <TargetFramework>net10.0</TargetFramework> in its Directory.Build.props, to make every project single-target, loses that value when this line clears it. The project then multi-targets the default TargetFrameworks (net10.0;net9.0;net8.0;netstandard2.0;netstandard2.1). There is no warning. Only a TargetFramework written in the csproj body, which is evaluated after Sdk.props, has any effect. The extension SDKs' Sdk.props set TargetFramework without a condition too, so adding an "only if empty" guard there would do nothing: the core has already cleared the value by then.

This is not tracked anywhere yet. #91 covers package metadata properties overwritten from Directory.Build.props, and #55 / #72 cover test projects. None of them covers TargetFramework for libraries and apps.

Plan reference

The .NET 11 readiness spec deferred this on purpose and said it needs its own change.
docs/plans/dotnet-11-readiness.md L207-L222 @ 96df23f:

Sdk/Sdk.props's unconditional <TargetFramework></TargetFramework> clear … sets TargetFramework to an empty value. … a consumer setting TargetFramework in Directory.Build.props is silently overwritten, and only a setting in the csproj body survives. … Fixing it properly means stopping the core from clearing, which is a behavior change … That deserves its own change, not a ride along with a version bump.

What exists today: the unconditional clear at Sdk/Sdk.props:556 and the unconditional TargetFramework assignments in the extension SDKs' Sdk.props. Nothing detects or reports an overwritten value.

What's missing: a way for a value set in Directory.Build.props to survive, or at minimum a diagnostic when it is discarded.

Why it matters

A maintainer who wants a repository on one framework, for example an app repo or an experiment on net11.0 previews, puts TargetFramework in Directory.Build.props the usual MSBuild way. The build then quietly produces five framework assets, takes several times as long, and can fail on APIs the lower targets lack. Nothing points to the cause.

Suggested fix / acceptance criteria

Choose one of these approaches:

  1. Honour it. Make the core clear conditional on TargetFramework not having been set before Sdk.props. Capture the incoming value first, the way Sdk.props already records defaults for Sdk.targets to compare against. The extension SDKs then respect a pre-set value too.
  2. Diagnose it. Keep clearing the value, but record it first, and raise a KTSU warning or error naming Directory.Build.props when it was non-empty.

Either way:

  • There is a regression test in test/Sdk.Examples.Tests for a Directory.Build.props that sets TargetFramework, on the core SDK and on at least one extension SDK. It asserts option 1's single-target result, or option 2's diagnostic.
  • README and CHANGELOG call out the behaviour change. With option 1, any repository that has TargetFramework in a Directory.Build.props today switches from multi-targeting to single-targeting.

Dependencies: none. This fits with #91, the same "Directory.Build.props value is overwritten" family. It is independent of the .NET 11 flip (#57).

Activity

  1. added
    bug
    on Nov 5, 2026
  2. matt-edmondson commented on Nov 5, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions