Skip to content
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

Upgrade to dotnet8, and new plugin to list project dependencies #60

Merged
merged 8 commits into from
Nov 13, 2024
Merged
4 changes: 4 additions & 0 deletions src/NugetNinja.Core/Model/Workspace/NugetVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ public NugetVersion(string versionString)
public static bool operator !=(NugetVersion? lvs, NugetVersion? rvs) => !(lvs == rvs);

public static bool operator <(NugetVersion? lvs, NugetVersion? rvs) => lvs?.CompareTo(rvs) < 0;
public static bool operator <=(NugetVersion? lvs, NugetVersion? rvs) => lvs?.CompareTo(rvs) <= 0;

public static bool operator >(NugetVersion? lvs, NugetVersion? rvs) => lvs?.CompareTo(rvs) > 0;

public static bool operator >=(NugetVersion? lvs, NugetVersion? rvs) => lvs?.CompareTo(rvs) >= 0;


public object Clone() => new NugetVersion(SourceString);

public bool IsPreviewVersion() => !string.IsNullOrWhiteSpace(AdditionalText);
Expand Down
7 changes: 7 additions & 0 deletions src/NugetNinja.Core/Model/Workspace/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ private async Task SaveDocToDisk(HtmlDocument doc)
.Replace(@"></UserProperties>", " />")
.Replace(@"></EmbeddedResource>", " />")
.Replace(@"></ServiceWorker>", " />")
.Replace(@"></MauiIcon>"," />")
.Replace(@"></MauiSplashScreen>", " />")
.Replace(@"></MauiImage>", " />")
.Replace(@"></MauiFont>", " />")
.Replace(@"></MauiAsset>", " />")
.Replace(@"></Import>", " />")
.Replace(@"></Copy>", " />")
.Replace(@"></Using>", " />");

await File.WriteAllTextAsync(PathOnDisk, csprojText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,58 @@ private async IAsyncEnumerable<UselessPackageReference> AnalyzeProject(Project c
}
}

if (accessiblePackagesForThisProject.Any(pa => pa.Name == directReference.Name))
if (accessiblePackagesForThisProject.Any(pa => pa.Name == directReference.Name && pa.Version >= directReference.Version))
{
yield return new(context, directReference);
}
}
}

private bool GreaterVersion(NugetVersion version1, NugetVersion version2)
{
return version1 > version2;
}

public static int CompareNuGetVersions(string version1, string version2)
{
ErikApption marked this conversation as resolved.
Show resolved Hide resolved
if (version1 == null || version2 == null)
{
throw new ArgumentNullException("Both versions must be non-null");
}

string[] parts1 = version1.Split('.');
string[] parts2 = version2.Split('.');

int maxLength = Math.Max(parts1.Length, parts2.Length);

for (int i = 0; i < maxLength; i++)
{
int part1 = (i < parts1.Length) ? ParseVersionPart(parts1[i]) : 0;
int part2 = (i < parts2.Length) ? ParseVersionPart(parts2[i]) : 0;

if (part1 < part2)
{
return -1;
}
else if (part1 > part2)
{
return 1;
}
}

return 0;
}

private static int ParseVersionPart(string part)
{
if (int.TryParse(part, out int result))
{
return result;
}
else
{
// Handle pre-release labels (e.g., "alpha", "beta")
return int.MaxValue;
}
}
}
Loading