-
Notifications
You must be signed in to change notification settings - Fork 692
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
warning when dot is omitted from targetframework version in net5.0+ #3625
Conversation
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.
Can we use a better PR title? Whoever is hotseat the week this gets inserted into VS will have an easier time figuring out the "area" with a less cryptic PR title.
@@ -169,6 +169,10 @@ | |||
<data name="IsPackableFalseError" xml:space="preserve"> | |||
<value>This project cannot be packaged because packaging has been disabled. Add <IsPackable>true</IsPackable> to the project file to enable producing a package from this project.</value> | |||
</data> | |||
<data name="MissingRequiredDot" xml:space="preserve"> | |||
<value>Dots in TargetFramework versions are required. The missing dot in '{0}' might cause future breakage.</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.
@JonDouglas do you have comments about this user-facing error message?
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.
Dots in TargetFramework versions are required. The missing dot in '{0}' might cause future breakage.
->
The TargetFrameworkVersion value `{0}` was not recognized. It may be missing a dotted version number.
The TargetFrameworkVersion value `{0}` was not recognized. It may be missing a version number separated by periods.
or
The TargetFrameworkVersion value `{0}` is not valid. Ensure your TargetFrameworkVersion includes a dotted version number.
The TargetFrameworkVersion value `{0}` is not valid. Ensure your TargetFrameworkVersion includes a version number separated by periods.
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.
The framework is technically valid and understood...just might not work the way that customer intended it to.
In particular the problem is that net50
is parses to version 5.0
, and the eventual progression of NET will eventually lead to version 10.0, so if people still write frameworks with versions then net10
, it'd get parsed to 1.0
while they might expect it to parse to 10.0
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.
Yep, and we want to change the behavior of the customer to promote the best practice.
This is similar with mobile TFMs such as monoandroid10 vs. monoandroid10.0. One is 1.0 & the other is 10.0.
So TargetFramework = monoandroid, TargetFrameworkVersion = v1.0
If anything, we should be promoting the separator across the board, it's the best practice is it not? Everything in the NET 5 spec suggests to use a period separator for all TargetBlahVersion
properties.
The bigger question is best practices for the <TargetFramework>
element here. Is it period separator or not? Prior to .NET Core it looks like no, it doesn't matter. After .NET Core it seems that it should be included. Thoughts?
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.
Separator across the board is the right approach.
Everything in the NET 5 spec suggests to use a period separator for all TargetBlahVersion properties.
Those are not user defined usually.
The idea is that the TargetFramework property can be anything.
NuGet doesn't parse it, which is why the check is only happening at pack time.
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.
Shouldn't we create an issue on the SDK team, or contribute a pull request ourselves, to do it in the SDK instead? It doesn't make much sense to me to do at pack time. It should be done at restore, but only when the monikers were not provided and the TargetFramework property was parsed, hence why it can only be done in the SDK and not in NuGet.
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.
@zivkan So what I'm hearing is that the suggestion is to drop this PR in favor of doing this SDK-side in a more general way?
As far as whether to warn always or warn only for certain frameworks -- I think the concern was that this could get very noisy, very quickly for people. I mean even for us, we'd need to change a bunch of net45
/net472
items in our tests and projects?
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.
yes, my opinion is close this PR, and someone should make a change in the SDK instead.
The key is, do not warn if my csproj has:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>whatever</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'whatever' ">
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkIdentifier>
<TargetFrameworkMoniker>$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
</PropertyGroup>
</Project>
This csproj doesn't have a .
in the TargetFramework value, but it doesn't need one because it correctly sets the 3 other properties needed to correctly define the canonical target framework. Only when the SDK parses the TargetFramework value to set the other properties itself, in that situation warn about missing dots.
And yes, you're right about the noisy warnings. Just like this PR, we should only warn when the TFM ends up being TFI='.NETCoreApp' and TFV >= '5.0'. Or any TFI='.NETStandard' apparently.
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 think we should still do it on our side in pack because people can manually create packages. We should catch things like that in the nuspec and package folders.
{ | ||
var dotIdx = targetFramework.IndexOf('.'); | ||
var dashIdx = targetFramework.IndexOf('-'); | ||
var isDottedFwVersion = (dashIdx > -1 && dotIdx > -1 && dotIdx < dashIdx) || dotIdx > -1; |
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.
var isDottedFwVersion = (dashIdx > -1 && dotIdx > -1 && dotIdx < dashIdx) || dotIdx > -1; | |
var isDottedFwVersion = (dotIdx > -1 && dashIdx > dotIdx) || dotIdx > -1; |
if dotIdx > -1
and dashIdx > dotIdx
then we can imply that dashIdx > -1
. Hence removed that condition. Please help me understand why we need to check the presence of -
char in the string.
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 see that this code is executed only when packing via csproj, not nuspec. Don't we need this rule when packing using nuspec
?
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.
Please help me understand why we need to check the presence of - char in the string.
We need to check for the dash because the dot might be in the platform part of the tfm (net50-windows7.0
)
I see that this code is executed only when packing via csproj, not nuspec. Don't we need this rule when packing using nuspec?
I don't know why we do this, but I'm still figuring out how Pack works overall. @nkolev92 @zivkan do y'all have any idea what this difference is about?
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.
When we pack a nuspec, I don't believe that NuGet implicitly adds anything to the package. @zkat you should confirm, but I think it's 100% up to the customer writing he nuspec to explicitly define everything in the package.
However, this got me thinking, TargetFramework
is now just an alias. NuGet should not be using this string in the lib/<tfm>/
folder structure, it should be parsing the TargetFrameworkMoniker
and TargetPlatformMoniker
into a NuGetFramework, then calling
.GetShortFolderName(), which will correctly add the
.in
net5.0, even if it was missing in
TargetFramework`.
Maybe we need a test for this, but it shouldn't require a product change to pack. I'd say maybe there should be a warning about this for restore, but it's not really feasible for NuGet to do the check, I think the .NET SDK would need to. By the time it gets to NuGet, we don't know if the TargetFramework was parsed, and therefore needs the warning, or if it was just an alias, and therefore we should not warn. Hence I think it's the .NET SDK's responsibility if this should be warned.
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 mostly agree with @zivkan.
We should add a test/warning for the manual nuspec scenario. Beyond that, it think the SDK might make more sense.
Tbh, it's not a deal breaker if we can't add it I think. The templates are creating the correct things.
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 don't know if the nuspec pack is handled here.
Worth adding a test for that
var isNet5EraTfm = fw.Version.Major >= 5 && | ||
StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.NetCoreApp, fw.Framework); | ||
var isNetStandard = StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.NetStandard, fw.Framework); | ||
if (isNet5EraTfm || isNetStandard) |
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.
Why are we checking the netstandard versions?
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.
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.
There'll be no new versions of netstandard.
The true risk here is what happens when we hit net10.0
. The risk is not there with netstandard.
Keep in mind that there are existing packages/projects with netstandard. I see no reason to raise an extra warning for something that won't really affect them.
Co-authored-by: Kartheek Penagamuri <52756182+kartheekp-ms@users.noreply.github.com>
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.
3bddcfb
to
27d89d0
Compare
Any reason this wasn't merged yet? I'd love to close dotnet/runtime#34173. |
I'm closing this and making a single PR for all the .net5-related changes (or I might split them up later, but I'm working on a single branch right now) |
Fixes: NuGet/Home#9215