Only set UnsupportedTargetFrameworkVersion when NETCoreAppMaximumVersion exists #51961
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
External MSBuild SDKs (e.g., Microsoft.Build.Sql) that don't define
NETCoreAppMaximumVersionwere encountering confusing error messages about unsupported target framework versions, masking the actual error (missing SDK dependencies).Changes
'$(NETCoreAppMaximumVersion)' != ''to thePropertyGroupsettingUnsupportedTargetFrameworkVersioninMicrosoft.NET.SupportedTargetFrameworks.propsThis allows external SDKs to fail with their actual error message (e.g., missing NuGet.Build.Tasks.Pack) rather than triggering version compatibility checks intended only for .NET SDK projects.
Fixes #45009
Original prompt
This section details on the original issue you should resolve
<issue_title>Confusing error when non .NET sdk has no compatible targets</issue_title>
<issue_description>### Describe the bug
This bug occurred in one of our workflows when the runner updated to .NET 10. See Exceptions for the error message.
The "bug" being that this message is very vague and doesn't point toward the actual cause of the problem. My assumption is that this error is thrown because the Sql package doesn't relate to
NETCoreAppMaximumVersion(but I'm not sure).When I commented out the
UnsupportedTargetFrameworkVersionattribute in theMicrosoft.NET.SupportedTargetFrameworks.propsfile. It gave me an error that made much more sense and made it very easy to understand what actually was the problem and I could update the sql SDK:So I'm wondering if it was taken into account that there can also be different SDK packages than just base .NET sdks?
To Reproduce
Create a Database project that has an tag with Microsoft.Build.Sql that does not support .NET 10 (for example
<Sdk Name="Microsoft.Build.Sql" Version="1.0.0-rc1" />)Exceptions (if any)
C:\Program Files\dotnet\sdk\10.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.SupportedTargetFrameworks.props(36,9): error MSB4186: Invalid static method invocation syntax: "[MSBuild]::Add($(NETCoreAppMaximumVersion), 1)". Method '[MSBuild]::Add' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(a,b)). Check that all parameters are defined, are of the correct type, and are specified in the right order.Further technical details
details of dotnet --info
.NET SDK: Version: 10.0.100 Commit: b0f34d51fc Workload version: 10.0.100-manifests.355811b7 MSBuild version: 18.0.2+b0f34d51f
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100\
.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.
Host:
Version: 10.0.0
Architecture: x64
Commit: b0f34d51fc
.NET SDKs installed:
9.0.307 [C:\Program Files\dotnet\sdk]
10.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
<agent_instructions>Only set UnsupportedTargetFrameworkVersion if NETCoreAppMaximumVersion exists. That should avoid the unhelpful error message in this case.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@baronfel Do you have a sample reproduction or binlog that shows the context in more detail? You're pointing at a specific property usage, but I don't have enough of a sense of the surrounding context to understand if this is a bug against the .NET SDK or against the external Microsoft.Build.Sql MSBuild SDK.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.