Change default TargetFramework from net472 to netstandard2.1 for non-…#791
Conversation
…NetCoreBuild projects
| </PropertyGroup> | ||
|
|
||
|
|
||
| <!-- When user opts into .NET Framework for SQLCLR assemblies, override the TFV/TFM that was |
There was a problem hiding this comment.
How does the user "opt in" - and what if she chooses net48 ?
There was a problem hiding this comment.
Valid concern, thanks for catching this.
With this fix user opts in by setting in their .sqlproj.
Updated the implementation — instead of hardcoding net472, we now clear the stale TFV/TFM defaults whenever the user overrides TargetFramework, and let Microsoft.NET.Sdk's TargetFrameworkInference handle the resolution. This works for net472, net48, or any other valid TFM.
| <!-- If the user overrode TargetFramework from the netstandard2.1 default (e.g. net472, net48), | ||
| clear the TFV/TFM that Sdk.props pre-set so Microsoft.NET.Sdk can infer the correct values. --> | ||
| <PropertyGroup Condition="'$(NetCoreBuild)'=='false' AND '$(TargetFramework)' != 'netstandard2.1'"> | ||
| <TargetFrameworkVersion /> |
There was a problem hiding this comment.
you are setting these and then removing them? may add condition before setting?
There was a problem hiding this comment.
This is an MSBuild evaluation-order constraint. SDK-style projects evaluate in this order:
Sdk.props — before the project body
Project body — where the user may override
Sdk.targets — after the project body
We must pre-set TargetFrameworkVersion and TargetFrameworkMoniker in Sdk.props because VS design-time evaluation needs valid values before the full build runs. However, at Sdk.props time we can't know if the user will override TargetFramework in the project body.
So in Sdk.targets, if the user's TargetFramework differs from our default (netstandard2.1), we clear TFV/TFM so that Microsoft.NET.Sdk's TargetFrameworkInference.targets (imported immediately after) can derive the correct values from the actual TargetFramework.
I've also added tests that validate: when the user sets net472, TFV resolves to v4.7.2 and TFM to .NETFramework,Version=v4.7.2 (not the stale .NETStandard default).
@microsoft-github-policy-service agree |
…NetCoreBuild projects
Description
Updates the default TargetFramework in Sdk.props from net472 / .NETFramework to netstandard2.1 / .NETStandard for projects where NetCoreBuild is false (Visual Studio / non-CLI builds). This makes netstandard2.1 the baseline, while still allowing users to opt into net472 for SQLCLR assembly scenarios.
In addition, go through the checklist below and check each item as you validate it is either handled or not applicable to this change.
Code Changes