diff --git a/src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs b/src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs index 9b1b244486c8..d1fd028f7a1d 100644 --- a/src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs +++ b/src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Reflection; +using Microsoft.DotNet.Cli.CommandFactory.CommandResolution; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.NuGetPackageDownloader; using Microsoft.DotNet.Cli.Utils; @@ -292,7 +293,20 @@ private static async Task DownloadAndExtractPackage( using (FileStream packageStream = File.OpenRead(packagePath)) { PackageArchiveReader reader = new(packageStream); - version = new NuspecReader(reader.GetNuspec()).GetVersion(); + NuspecReader nuspecReader = new NuspecReader(reader.GetNuspec()); + version = nuspecReader.GetVersion(); + bool requireLicenseAcceptance = nuspecReader.GetRequireLicenseAcceptance(); + // If the package requires license acceptance, we need to ask the user to accept it + // TODO: Find a better way to handle this + if (requireLicenseAcceptance) + { + Console.WriteLine($"The package {packageId} requires license acceptance. Please accept the license to continue. [y]"); + if (!Console.ReadKey().Key.Equals(ConsoleKey.Y)) + { + throw new ToolPackageException($"User did not accept the license for package {packageId}."); + } + } + var packageHash = Convert.ToBase64String(new CryptoHashProvider("SHA512").CalculateHash(reader.GetNuspec())); var hashPath = new VersionFolderPathResolver(packagesRootPath).GetHashPath(packageId.ToString(), version);