Repository navigation
Fix version parsing in dotnet-validate - #1261
Merged
clairernovotny merged 1 commit intoMar 7, 2021
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I noticed that using
dotnet-validatedid not use provide version as expected. It seemed to be ignored (problem 1):Also, four-number versions were rejected (problem 2):

... which of course if wrong since NuGet is okay with this:

https://nugettoolsdev.azurewebsites.net/5.8.0/parse-version?version=2.0.2.1
To fix problem 1 and problem 2, I just provided a
parseArgumentparameter to the appropriateOption<T>overload.I also noticed this interesting comment where
nullwas not being passed by System.CommandLine when-vis not specified by the user (problem 3):NuGetPackageExplorer/dotnet-validate/Program.cs
Lines 116 to 120 in 118e988
I dug into the System.CommandlLine implementation and found that it was calling an arbitrary constructor on
NuGetVersioninstead of parsing the provided string.https://github.com/dotnet/command-line-api/blob/d87107bd40bb629fbee3ae2444b3a04cf631191d/src/System.CommandLine/Binding/ModelBinder.cs#L166-L169
Essentially, it seems to be picking the longest constructor where it can make guesses about the constructor parameters.
From my debugging, it is picking this one:
https://github.com/NuGet/NuGet.Client/blob/63255047fe7052cc33b763356ff995d9166f719e/src/NuGet.Core/NuGet.Versioning/NuGetVersion.cs#L116-L119
... and passing in default values for all of those types.
This is why we were seeing the
0.0.0version -- because0is the default forintand the rest of thestringparameters receive null, resulting in a0.0.0version.To fix problem 3 I set a
nulldefault value onRunRemoteCommandwhich makeSystem.CommandLineskip the arbitrary constructor flow and just provide `null.