Skip to content

Improve empty TargetFramework diagnostic with dedicated NETSDK1241 - #54335

Merged
marcpopMSFT merged 5 commits into
mainfrom
copilot/fix-targetframework-missing-error
Jun 9, 2026
Merged

marcpopMSFT merged 5 commits into
mainfrom
copilot/fix-targetframework-missing-error

Conversation

Copilot AI commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

When TargetFramework is present but empty, SDK evaluation currently reports it as an unrecognized TFM (''), which is misleading and often followed by secondary infrastructure errors. This change distinguishes the empty-value case from genuinely invalid TFMs while preserving existing behavior for non-empty invalid inputs.

  • Target framework inference diagnostics

    • In Microsoft.NET.TargetFrameworkInference.targets, split _CheckForUnsupportedTargetFramework into:
      • empty $(TargetFramework) → dedicated error resource
      • non-empty single TFM → existing “not recognized” error
      • semicolon-delimited value → existing multi-targeting guidance error
  • New resource message (new error code)

    • Added TargetFrameworkEmpty in Strings.resx as the last entry:
      • NETSDK1241: The TargetFramework property is empty. Specify a value for the TargetFramework property in your project file.
    • Keeps existing NETSDK1013 for non-empty unrecognized TFMs.
  • Strings.resx guard update

    • Updated the trailing “latest message added” guard comment in Strings.resx to TargetFrameworkEmpty to preserve duplicate-code protection for parallel PRs.
  • Focused test expectation update

    • Updated GivenThatWeWantToBuildALibrary.It_fails_gracefully_if_targetframework_is_empty to assert the new empty-property message.
    • Existing invalid/non-empty TFM test remains unchanged, preserving distinction.
  • Copilot instructions update

    • Updated .github/copilot-instructions.md to document NETSDK diagnostic-code workflow for Strings.resx:
      • use the next available NETSDK code,
      • append the new entry at the end of the file,
      • update the trailing guard comment.
  • Merge + localization regeneration

    • Merged main and resolved Strings.resx conflict by preserving newly added diagnostics from main and assigning the next available code to TargetFrameworkEmpty.
    • Regenerated src/Tasks/Common/Resources/xlf/Strings.*.xlf to match the updated resource text/code.
<NETSdkError Condition="'$(TargetFramework)' == ''"
             ResourceName="TargetFrameworkEmpty" />

<NETSdkError Condition="'$(TargetFramework)' != '' and !$(TargetFramework.Contains(';'))"
             ResourceName="CannotInferTargetFrameworkIdentifierAndVersion"
             FormatArguments="$([MSBuild]::Escape('$(TargetFramework)'))" />

Copilot AI changed the title [WIP] Fix error when TargetFramework is missing in projects Improve NETSDK1013 clarity when TargetFramework is empty May 15, 2026
Copilot AI requested a review from marcpopMSFT May 15, 2026 22:26
Comment thread src/Tasks/Common/Resources/Strings.resx Resolved
@marcpopMSFT

Copy link
Copy Markdown
Member

@copilot This PR still reuses an existing error code. What you should do instead is update the string to be the last one in the Strings.resx file and be one higher than the last one in the list. Then update the comment that's at the end of that file which is there to guard against duplicating error codes from code flow.

Please make this change and update the copilot instructions to mention how we handle netsdk error codes in that file.

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot This PR still reuses an existing error code. What you should do instead is update the string to be the last one in the Strings.resx file and be one higher than the last one in the list. Then ...

Updated in commit 65aa650. The empty TargetFramework diagnostic now uses a new code (NETSDK1238) as the last entry in Strings.resx, the trailing guard comment was updated to TargetFrameworkEmpty, and .github/copilot-instructions.md now documents the NETSDK error-code assignment convention for that file.

Copilot AI changed the title Improve NETSDK1013 clarity when TargetFramework is empty Improve empty TargetFramework diagnostic with dedicated NETSDK1238 May 27, 2026
@marcpopMSFT

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts with main and rebuild to regenerate the xlf files.

Copilot AI commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts with main and rebuild to regenerate the xlf files.

Resolved by merging main and fixing the Strings.resx conflict in commit ef09193. I rebuilt locally to regenerate localization outputs; TargetFrameworkEmpty is now assigned NETSDK1241 and the corresponding src/Tasks/Common/Resources/xlf/Strings.*.xlf files were updated.

Copilot AI changed the title Improve empty TargetFramework diagnostic with dedicated NETSDK1238 Improve empty TargetFramework diagnostic with dedicated NETSDK1241 May 28, 2026
@marcpopMSFT
marcpopMSFT marked this pull request as ready for review May 29, 2026 18:58
Copilot AI review requested due to automatic review settings May 29, 2026 18:58
@marcpopMSFT

Copy link
Copy Markdown
Member

Tested and confirm it works with both empty TF and TFs and correctly doesn't flag with a valid TFs but no TF.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves SDK diagnostics for projects where TargetFramework is present but empty by introducing a dedicated NETSDK1241 message instead of reporting the value as an unrecognized TFM.

Changes:

  • Splits unsupported TargetFramework handling into empty, invalid single-TFM, and semicolon-delimited cases.
  • Adds the new TargetFrameworkEmpty resource and regenerated localization entries.
  • Updates test expectations and Copilot guidance for NETSDK diagnostic additions.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.github/copilot-instructions.md Documents workflow for adding new NETSDK error messages.
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.TargetFrameworkInference.targets Emits TargetFrameworkEmpty for empty TargetFramework.
src/Tasks/Common/Resources/Strings.resx Adds NETSDK1241 resource and updates guard comment.
src/Tasks/Common/Resources/xlf/Strings.cs.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.de.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.es.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.fr.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.it.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.ja.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.ko.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.pl.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.ru.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.tr.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf Adds localized placeholder entry for TargetFrameworkEmpty.
test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs Updates empty TargetFramework test expectation.

@ellahathaway ellahathaway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff (targets logic, Strings.resx, XLF updates, and the test change) and I don’t see any correctness or regression issues. The empty TargetFramework path now gets a dedicated NETSDK1241 diagnostic while preserving behavior for non-empty invalid and semicolon-delimited cases. Approved.

@marcpopMSFT
marcpopMSFT merged commit 4789820 into main Jun 9, 2026
21 of 23 checks passed
@marcpopMSFT
marcpopMSFT deleted the copilot/fix-targetframework-missing-error branch June 9, 2026 15:01
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 10, 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.

Error when TargetFramework missing is problematic

5 participants