-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TargetFramework(s) unexpected check #11285
base: main
Are you sure you want to change the base?
Conversation
@@ -10,7 +10,8 @@ Report codes are chosen to conform to suggested guidelines. Those guidelines are | |||
| [BC0104](#bc0104---projectreference-is-preferred-to-reference) | Warning | N/A | 9.0.200 | ProjectReference is preferred to Reference. | | |||
| [BC0105](#bc0105---embeddedresource-should-specify-culture-metadata) | Warning | N/A | 9.0.200 | Culture specific EmbeddedResource should specify Culture metadata. | | |||
| [BC0106](#bc0106---copytooutputdirectoryalways-should-be-avoided) | Warning | N/A | 9.0.200 | CopyToOutputDirectory='Always' should be avoided. | | |||
| [BC0107](#bc0107---targetframework-and-targetframeworks-specified-together) | Warning | N/A | 9.0.200 | TargetFramework and TargetFrameworks specified together. | | |||
| [BC0107](#bc0107---targetframework-and-targetframeworks-specified-together) | Warning | N/A | 9.0.200 | TargetFramework or TargetFrameworks specified in non-SDK style project. | | |||
| [BC0108](#bc0108---targetframework-or-targetframeworks-specified-in-non-sdk-style-project) | Warning | N/A | 9.0.300 | TargetFramework and TargetFrameworks specified together. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| [BC0108](#bc0108---targetframework-or-targetframeworks-specified-in-non-sdk-style-project) | Warning | N/A | 9.0.300 | TargetFramework and TargetFrameworks specified together. | | |
| [BC0108](#bc0108---targetframework-or-targetframeworks-specified-in-non-sdk-style-project) | Warning | N/A | 9.0.300 | TargetFramework or TargetFrameworks specified in non-SDK style project. | |
@@ -2198,6 +2198,14 @@ Utilization: {0} Average Utilization: {1:###.0}</value> | |||
<value>Project {0} specifies 'TargetFrameworks' property '{1}' and 'TargetFramework' property '{2}' at the same time. This will lead to 'TargetFrameworks' being ignored and build will behave as single-targeted.</value> | |||
<comment>Terms in quotes are not to be translated.</comment> | |||
</data> | |||
<data name="BuildCheck_BC0108_Title" xml:space="preserve"> | |||
<value>'TargetFramework' nor 'TargetFrameworks' property should not be specified in non-SDK style projects.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<value>'TargetFramework' nor 'TargetFrameworks' property should not be specified in non-SDK style projects.</value> | |
<value>'TargetFramework' and 'TargetFrameworks' properties are not respected and should not be specified in projects that do not use the .NET SDK.</value> |
<comment>Terms in quotes are not to be translated.</comment> | ||
</data> | ||
<data name="BuildCheck_BC0108_MessageFmt" xml:space="preserve"> | ||
<value>Project {0} specifies 'TargetFramework(s)' property '{1}', while it's not SDK-style project. Those properties are not understood by legacy-style projects and have no impact.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How dare you use the forbidden word? 😅
<value>Project {0} specifies 'TargetFramework(s)' property '{1}', while it's not SDK-style project. Those properties are not understood by legacy-style projects and have no impact.</value> | |
<value>Project {0} specifies 'TargetFramework(s)' property '{1}', which does not use the .NET SDK. Those properties are not understood by projects that import C# targets directly.</value> |
context.Data.EvaluatedProperties.TryGetValue(PropertyNames.TargetFramework, out framework)) && | ||
!string.IsNullOrEmpty(framework ?? frameworks)) | ||
{ | ||
// {0} specifies 'TargetFrameworks' property '{1}' and 'TargetFramework' property '{2}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
string? frameworks = null; | ||
string? framework = null; | ||
// This is not SDK style project | ||
if ((!context.Data.EvaluatedProperties.TryGetValue(PropertyNames.UsingMicrosoftNETSdk, out string? usingSdkStr) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading your conditions correctly here, I think this would fire on a C++/CLI vcxproj targeting .NET 8--but shouldn't.
|
||
'TargetFramework' or 'TargetFrameworks' control the project output targets in modern .NET SDK-style projects. The older non-SDK style projects ('legacy style' projects) interprets different properties for similar mechanism (like 'TargetFrameworkVersion') and the 'TargetFramework' or 'TargetFrameworks' are silently ignored. | ||
|
||
Make sure the Target Framework targetting is done by properly understood mechanism. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure the Target Framework targetting is done by properly understood mechanism. | |
Make sure the Target Framework is specified appropriately for your project. |
|
||
"'TargetFramework' nor 'TargetFrameworks' property should not be specified in non-SDK style projects." | ||
|
||
'TargetFramework' or 'TargetFrameworks' control the project output targets in modern .NET SDK-style projects. The older non-SDK style projects ('legacy style' projects) interprets different properties for similar mechanism (like 'TargetFrameworkVersion') and the 'TargetFramework' or 'TargetFrameworks' are silently ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't say "legacy". And the style of the project isn't relevant, the actual SDK used is what matters (this is a hill I'll die on, "SDK-style" is horribly overused).
[Fact] | ||
public void TFMinNonSdkCheckTest() | ||
{ | ||
string content = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say this is an example of a project that shouldn't fire this: it's not controlling an output DLL's TF, but it might be doing something on purpose . . .
Fixes #10635
Context
TargetFramework(s) are honored only in SDK-style projects - emit diagnostic if the property is used in legacy style project
Testing
Targetted test