diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index c6e951c6..bbe5e217 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -26,7 +26,10 @@ jobs: uses: actions/setup-dotnet@v2 with: dotnet-version: "6.0.x" # SDK Version to use (x uses the latest version). - include-prerelease: true + - name: Setup dotnet 7.0.x + uses: actions/setup-dotnet@v2 + with: + dotnet-version: "7.0.x" # SDK Version to use (x uses the latest version). # dotnet restore - name: restore run: dotnet restore diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 32a12f8c..5c226861 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,6 +30,12 @@ jobs: uses: actions/setup-dotnet@v2 with: dotnet-version: "6.0.x" # SDK Version to use (x uses the latest version). + env: + NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + - name: Setup dotnet 7.0.x + uses: actions/setup-dotnet@v2 + with: + dotnet-version: "7.0.x" # SDK Version to use (x uses the latest version). include-prerelease: true env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} @@ -47,10 +53,10 @@ jobs: run: dotnet pack --configuration Release # publish the package - name: Publish the artifact - run: dotnet publish -f net5.0 -c Release -o ./artifacts + run: dotnet publish -f net7.0 -c Release -o ./artifacts # publish the package to package folder - name: Publish the artifact - run: dotnet publish -f net5.0 -c Release -o ./package + run: dotnet publish -f net7.0 -c Release -o ./package # Add nuget package - name: Nuget package run: dotnet pack -c Release -o ./artifacts diff --git a/src/InvalidLicensesException.cs b/src/InvalidLicensesException.cs index e742eb9b..9fd06d0c 100644 --- a/src/InvalidLicensesException.cs +++ b/src/InvalidLicensesException.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; - namespace NugetUtility { public class InvalidLicensesException : Exception diff --git a/src/LibraryNameAndVersionComparer.cs b/src/LibraryNameAndVersionComparer.cs index 27bdc26d..3f5f6c6c 100644 --- a/src/LibraryNameAndVersionComparer.cs +++ b/src/LibraryNameAndVersionComparer.cs @@ -9,7 +9,7 @@ public class LibraryNameAndVersionComparer : IEqualityComparer public bool Equals([AllowNull] LibraryInfo x, [AllowNull] LibraryInfo y) { - return x?.PackageName == y?.PackageName + return x?.PackageName == y?.PackageName && x?.PackageVersion == y?.PackageVersion; } diff --git a/src/LicenseToUrlMappings.cs b/src/LicenseToUrlMappings.cs index 18d535eb..d88f77c1 100644 --- a/src/LicenseToUrlMappings.cs +++ b/src/LicenseToUrlMappings.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace NugetUtility { diff --git a/src/Methods.cs b/src/Methods.cs index c0a93e59..046b0ebc 100644 --- a/src/Methods.cs +++ b/src/Methods.cs @@ -36,7 +36,7 @@ public class Methods private readonly PackageOptions _packageOptions; private readonly XmlSerializer _serializer; - internal static bool IgnoreSslCertificateErrorCallback(HttpRequestMessage message, System.Security.Cryptography.X509Certificates.X509Certificate2 cert, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) + public static bool IgnoreSslCertificateErrorCallback(HttpRequestMessage message, System.Security.Cryptography.X509Certificates.X509Certificate2 cert, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) => true; // Search nuspec in local cache (Fix for linux distro) @@ -61,7 +61,7 @@ public Methods(PackageOptions packageOptions) } httpClientHandler.Proxy = myProxy; } - + if (packageOptions.IgnoreSslCertificateErrors) { httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => IgnoreSslCertificateErrorCallback(message, cert, chain, sslPolicyErrors); @@ -92,9 +92,10 @@ public async Task GetNugetInformationAsync(string project, IEnumera { try { - if (_packageOptions.PackageFilter.Any (p => string.Compare (p, packageWithVersion.Name, StringComparison.OrdinalIgnoreCase) == 0) || - _packageOptions.PackageRegex?.IsMatch (packageWithVersion.Name) == true) { - WriteOutput (packageWithVersion.Name + " skipped by filter.", logLevel : LogLevel.Verbose); + if (_packageOptions.PackageFilter.Any(p => string.Compare(p, packageWithVersion.Name, StringComparison.OrdinalIgnoreCase) == 0) || + _packageOptions.PackageRegex?.IsMatch(packageWithVersion.Name) == true) + { + WriteOutput(packageWithVersion.Name + " skipped by filter.", logLevel: LogLevel.Verbose); continue; } @@ -108,7 +109,7 @@ public async Task GetNugetInformationAsync(string project, IEnumera if (!string.IsNullOrEmpty(version)) { - WriteOutput($"Package '{packageWithVersion.Name}', version requirement {packageWithVersion.Version} resolved to version {version} from local cache", logLevel: LogLevel.Verbose); + WriteOutput($"Package '{packageWithVersion.Name}', version requirement {packageWithVersion.Version} resolved to version {version} from local cache", logLevel: LogLevel.Verbose); var lookupKey = Tuple.Create(packageWithVersion.Name, version); if (_requestCache.TryGetValue(lookupKey, out var package)) @@ -129,7 +130,7 @@ public async Task GetNugetInformationAsync(string project, IEnumera await ReadNuspecFile(project, licenses, packageWithVersion.Name, version, lookupKey, textReader); continue; } - catch(Exception exc) + catch (Exception exc) { // Ignore errors in local cache, try online call WriteOutput($"ReadNuspecFile error, package '{packageWithVersion.Name}', version {version}", exc, LogLevel.Verbose); @@ -195,7 +196,7 @@ public async Task GetNugetInformationAsync(string project, IEnumera throw; } } - } + } else { WriteOutput($"Package '{packageWithVersion.Name}', version {packageWithVersion.Version} not found in NuGet", logLevel: LogLevel.Error); @@ -240,7 +241,7 @@ private async Task ResolvePackageVersionFromNugetServerAsync(string name } #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously - private async Task > GetVersionsFromLocalCacheAsync(string packageName) + private async Task> GetVersionsFromLocalCacheAsync(string packageName) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { // Nuget saves packages in lowercase format, and we should look for lowercase folders only to allow Linux case-sensitive folder enumeration to succeed @@ -253,7 +254,7 @@ private async Task ResolvePackageVersionFromNugetServerAsync(string name { return Enumerable.Empty(); } - + } private async Task> GetVersionsFromNugetServerAsync(string packageName) @@ -387,7 +388,7 @@ public IEnumerable GetProjectReferences(string projectPath) } IEnumerable references = Array.Empty(); - + // First use project.assets.json, if this option is enabled. if (_packageOptions.UseProjectAssetsJson) { @@ -669,29 +670,36 @@ private async Task HandleLicensing(Package package) _licenseFileCache[key] = await GetNuGetPackageFileResult(package.Metadata.Id, package.Metadata.Version, package.Metadata.License.Text); } - private string GetOutputFilename (string defaultName) { - string outputDir = GetExportDirectory (); + private string GetOutputFilename(string defaultName) + { + string outputDir = GetExportDirectory(); - return string.IsNullOrWhiteSpace (_packageOptions.OutputFileName) ? - Path.Combine (outputDir, defaultName) : - Path.Combine (outputDir, _packageOptions.OutputFileName); + return string.IsNullOrWhiteSpace(_packageOptions.OutputFileName) ? + Path.Combine(outputDir, defaultName) : + Path.Combine(outputDir, _packageOptions.OutputFileName); } - public string GetExportDirectory () { + public string GetExportDirectory() + { string outputDirectory = string.Empty; - if (!string.IsNullOrWhiteSpace (_packageOptions.OutputDirectory)) { - if (_packageOptions.OutputDirectory.EndsWith ('/')) { - outputDirectory = Path.GetDirectoryName (_packageOptions.OutputDirectory); - } else { - outputDirectory = Path.GetDirectoryName (_packageOptions.OutputDirectory + "/"); + if (!string.IsNullOrWhiteSpace(_packageOptions.OutputDirectory)) + { + if (_packageOptions.OutputDirectory.EndsWith('/')) + { + outputDirectory = Path.GetDirectoryName(_packageOptions.OutputDirectory); + } + else + { + outputDirectory = Path.GetDirectoryName(_packageOptions.OutputDirectory + "/"); } - if (!Directory.Exists (outputDirectory)) { - Directory.CreateDirectory (outputDirectory); + if (!Directory.Exists(outputDirectory)) + { + Directory.CreateDirectory(outputDirectory); } } - outputDirectory = string.IsNullOrWhiteSpace (outputDirectory) ? Environment.CurrentDirectory : outputDirectory; + outputDirectory = string.IsNullOrWhiteSpace(outputDirectory) ? Environment.CurrentDirectory : outputDirectory; return outputDirectory; } @@ -935,9 +943,11 @@ public List HandleDeprecateMSFTLicense(List libraries) return result; } - public async Task ExportLicenseTexts (List infos) { - var directory = GetExportDirectory (); - foreach (var info in infos.Where (i => !string.IsNullOrEmpty (i.LicenseUrl))) { + public async Task ExportLicenseTexts(List infos) + { + var directory = GetExportDirectory(); + foreach (var info in infos.Where(i => !string.IsNullOrEmpty(i.LicenseUrl))) + { var source = info.LicenseUrl; var outpath = Path.Combine(directory, $"{info.PackageName}_{info.PackageVersion}.txt"); var outpathhtml = Path.Combine(directory, $"{info.PackageName}_{info.PackageVersion}.html"); @@ -1054,10 +1064,10 @@ private string CorrectUri(string uri) uri = uri.Replace("/blob/", "/raw/", StringComparison.Ordinal); } - /* if (uri.Contains("/dotnet/corefx/", StringComparison.Ordinal)) - { - uri = uri.Replace("/dotnet/corefx/", "/dotnet/runtime/", StringComparison.Ordinal); - }*/ + /* if (uri.Contains("/dotnet/corefx/", StringComparison.Ordinal)) + { + uri = uri.Replace("/dotnet/corefx/", "/dotnet/runtime/", StringComparison.Ordinal); + }*/ return uri; } diff --git a/src/NugetUtility.csproj b/src/NugetUtility.csproj index 11c59a02..9bda5c25 100644 --- a/src/NugetUtility.csproj +++ b/src/NugetUtility.csproj @@ -2,14 +2,17 @@ Exe - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net5.0;net6.0;net7.0 + false + latest + false true true DotnetTool git dotnet-project-licenses dotnet-project-licenses - 2.4.0 + 2.5.0 Tom Chavakis, Lexy2, senslen - .NET Core Tool to print a list of the licenses of a projects diff --git a/tests/NugetUtility.Tests/NugetUtility.Tests.csproj b/tests/NugetUtility.Tests/NugetUtility.Tests.csproj index 1ffa133d..9ca2b47d 100644 --- a/tests/NugetUtility.Tests/NugetUtility.Tests.csproj +++ b/tests/NugetUtility.Tests/NugetUtility.Tests.csproj @@ -1,7 +1,10 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net5.0;net6.0;net7.0; + false + false + latest false