-
Notifications
You must be signed in to change notification settings - Fork 701
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 support for net5.0-<platform> #3339
Conversation
test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTests.cs
Outdated
Show resolved
Hide resolved
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.
🕐
looks very good. found a few minor things so far.
773c045
to
51a29a5
Compare
test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkParseTests.cs
Outdated
Show resolved
Hide resolved
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.
Looks good so far.
A few questions/suggestions.
No complaints on the public API part.
test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkParseTests.cs
Outdated
Show resolved
Hide resolved
f1082db
to
b696695
Compare
caad68f
to
962a44b
Compare
@@ -134,6 +137,20 @@ public bool TryGetShortProfile(string frameworkIdentifier, string profile, out s | |||
return TryConvertOrNormalize(profile, _profilesToShortName, _profileShortToLong, out profileShortName); | |||
} | |||
|
|||
public bool TryGetPlatform(string frameworkIdentifier, Version frameworkVersion, string platformIdentifier, out string platformShortName) |
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.
Are there null checks needed?
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 platformIdentifier is not used for an identification is this intended?
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.
Do we need UnitTests for this method?
@@ -33,6 +33,11 @@ interface IFrameworkNameProvider | |||
/// </summary> | |||
bool TryGetShortProfile(string frameworkIdentifier, string profile, out string profileShortName); | |||
|
|||
/// <summary> | |||
/// Get the official platform name from the short name. |
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.
Isn't it the other way: "Get the official platform short name from the platform name" ? The out argument is platformShortName
@@ -73,6 +74,8 @@ public FrameworkNameProvider(IEnumerable<IFrameworkMappings> mappings, IEnumerab | |||
_profilesToShortName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |||
_identifierShortToLong = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |||
_profileShortToLong = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |||
_platformToShortName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |||
_platformShortToLong = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |||
_portableFrameworks = new Dictionary<int, HashSet<NuGetFramework>>(); |
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.
Added 2 dictionaries( _platformToShortName, _platformShortToLong ) are initialized values, but never used.
Why is that?
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.
oops, it's a leftover from a previous iteration.
bool? result = _cache.GetOrAdd(cacheKey, (Func<CompatibilityCacheKey, bool>)((key) | ||
=> { return IsCompatibleCore(target, candidate) == true; })); | ||
bool? result = _cache.GetOrAdd(cacheKey, (Func<CompatibilityCacheKey, bool>)((key) | ||
=> |
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 simplify this part like bool? result = _cache.GetOrAdd(cacheKey, IsCompatibleCore(target, candidate) == true);
Otherwise very hard to read and understand.
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.
This looks to me like a re-formatting of existing code, but its functionality hasn't changed at all. I'm all for simplifying syntax, but I consider it out of scope for the PR (I wouldn't complain if it's improved, but I wouldn't hold up the PR because of it)
/// True if the platform is non-empty | ||
/// </summary> | ||
public bool HasPlatform | ||
{ |
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 more modern syntax here? public bool HasPlatform => !string.IsNullOrEmpty(Platform);
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 rather keep things consistent with the rest of the file, and I think it's out of scope to change all the other ones that work this way.
@@ -92,18 +92,19 @@ public static NuGetFramework ParseFrameworkName(string frameworkName, IFramework | |||
// if the first part is a special framework, ignore the rest | |||
if (!TryParseSpecialFramework(parts[0], out result)) | |||
{ |
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.
Just in case add parts.Any()
if expecting at least 1 item in array which is parts[0] for not to get index out of range exception.
if (parts.Any() && !TryParseSpecialFramework(parts[0], out result))
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 you know the data type, using .Length > 0
or .Count > 0
is a lot faster than using LINQ to do the same. Of course, this one thing is such a small part of the overall execution that in customer experience % terms it'll be just about zero, but I personally encourage people to avoid LINQ where possible.
bool validProfile = FrameworkConstants.FrameworkProfiles.Contains(profileShort); | ||
if (validProfile) | ||
// Find a platform version if it exists and yank it out | ||
var platformChars = profileShort; |
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.
No need this extra platformChars
variable here, keep using profileShort
unless we do profileShort.ToCharArray()
, but most likely no need;
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.
This improves the readability because the 3rd part can be either profile or platform depending on the context.
I'd expect both of these to compile to the same thing anyways.
@nkolev92 I've sent a designs PR to cover this: dotnet/designs#130 |
bool? result = _cache.GetOrAdd(cacheKey, (Func<CompatibilityCacheKey, bool>)((key) | ||
=> { return IsCompatibleCore(target, candidate) == true; })); | ||
bool? result = _cache.GetOrAdd(cacheKey, (Func<CompatibilityCacheKey, bool>)((key) | ||
=> |
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.
This looks to me like a re-formatting of existing code, but its functionality hasn't changed at all. I'm all for simplifying syntax, but I consider it out of scope for the PR (I wouldn't complain if it's improved, but I wouldn't hold up the PR because of it)
// Always use decimals and 2+ digits for netstandard and | ||
// netcoreapp, or if any parts of the version are over 9 | ||
// we need to use decimals |
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 wouldn't have noticed if you didn't reformat this comment, but I don't believe this is correct any longer. net5.0 and above (net5Era) should also be using ".0" at the end.
Well, technically net5
will work just fine, but we want to make sure any time we (or the SDK, or anything else calling NuGet's APIs) write the short name, we always use the ".0" version, so customers are used to that syntax for when "10.0" comes along. But I'm not sure if this is a non-net5era codepath, so maybe it's ok.
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.
net5.0 is netcoreapp everywhere internally, so the comment is accurate, and the behavior is correct.
@@ -92,18 +92,19 @@ public static NuGetFramework ParseFrameworkName(string frameworkName, IFramework | |||
// if the first part is a special framework, ignore the rest | |||
if (!TryParseSpecialFramework(parts[0], out result)) | |||
{ |
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 you know the data type, using .Length > 0
or .Count > 0
is a lot faster than using LINQ to do the same. Of course, this one thing is such a small part of the overall execution that in customer experience % terms it'll be just about zero, but I personally encourage people to avoid LINQ where possible.
....Tests/NuGet.VisualStudio.Implementation.Test/Extensibility/VsFrameworkCompatibilityTests.cs
Show resolved
Hide resolved
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.
Looks great overall.
It's been a long journey, where the bulk of work was agreeing to the right design :)
Great job!
2 smaller comments left. First one is more important and I feel more confident about it.
2nd one is up to you and based on your analysis.
-
I think GetShortFolderName should normalize by providing the same casing. See: https://nugettoolsdev.azurewebsites.net/5.5.0-preview.2.6382/parse-framework?framework=NEtcoreapp1.0 and https://nugettoolsdev.azurewebsites.net/5.5.0-preview.2.6382/parse-framework?framework=NEtcoreapp1.0. Maybe I missed where it's getting normalized, so let me know.
-
What's the guidance for customers that can't use the extensibility framework API. Will anyone of note be affected? Do we need an issue tracking that.
src/NuGet.Clients/NuGet.VisualStudio.Implementation/Extensibility/VsFrameworkCompatibility.cs
Outdated
Show resolved
Hide resolved
bool validProfile = FrameworkConstants.FrameworkProfiles.Contains(profileShort); | ||
if (validProfile) | ||
// Find a platform version if it exists and yank it out | ||
var platformChars = profileShort; |
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.
This improves the readability because the 3rd part can be either profile or platform depending on the context.
I'd expect both of these to compile to the same thing anyways.
....Tests/NuGet.VisualStudio.Implementation.Test/Extensibility/VsFrameworkCompatibilityTests.cs
Show resolved
Hide resolved
2fde260
to
3e3d094
Compare
Fixes: NuGet/Home#9240 add TFI and TFV arguments + return null for GetNearest stop verifying platform names let bad frameworkname parses fail explosively fix tests more PR feedback fixes normalize platform shortnames and suppress resulting warning
3e3d094
to
d576239
Compare
@nkolev92 I've created an issue for it: NuGet/Home#9650 |
Fixes: NuGet/Home#9240
This PR adds support for
net5.0-<platform>
toNuGetFramework
and related classes.This isn't quite ready to merge, but I'd like to start getting reviews about the stuff that's already there. It turns out that I was missing a lot of stuff in NuGet/Home#9382, which I can go back and update the document with, although I'm tempted to just drop that PR altogether in favor of a straight-up implementation.