adamreeve / semver.net

Semantic versioning for .NET
MIT License
117 stars 22 forks source link

Parse version without a minor version number #63

Closed devklick closed 5 months ago

devklick commented 5 months ago

Hello,

Is it possible to construct a Version/parse a string into a Version without a minor version?

For example, I'm hoping for something like the following:

var version = SemanticVersioning.Version.Parse("1.2");
Console.WriteLine(version); // 1.2.0

At the moment, this throws an ArgumentException

Invalid version string: 1.2

I thought maybe passing loose = true would solve the issue but unfortunately not.

Going by the npm semver readme, it seems maybe this should actually be treated as 1.2.x:

A partial version range is treated as an X-Range, so the special character is in fact optional.

1.2 := 1.2.x := >=1.2.0 <1.3.0-0
anatawa12 commented 5 months ago

If you're talking about version range like 1.2.x, I think you should use SemanticVersioning.Range class instead of SemanticVersioning.Version and SemanticVersioning.Range already accepts "1.2" as >=1.2.0 < 1.3.0--

https://dotnetfiddle.net/cMYhva

devklick commented 5 months ago

Yeah range makes more sense in this scenario, thanks.