diff --git a/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs b/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs index a861993465c8..178463be71e9 100644 --- a/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs +++ b/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs @@ -131,14 +131,10 @@ public async Task DownloadPackageAsync(PackageId packageId, string.Format(LocalizableStrings.IsNotFoundInNuGetFeeds, packageId, source.Source)); } - string nupkgPath = downloadFolder == null || !downloadFolder.HasValue - ? Path.Combine(_packageInstallDir.Value, packageId.ToString(), - resolvedPackageVersion.ToNormalizedString(), - $"{packageId}.{resolvedPackageVersion.ToNormalizedString()}.nupkg") - : Path.Combine(downloadFolder.Value.Value, - $"{packageId}.{resolvedPackageVersion.ToNormalizedString()}.nupkg"); - + var pathResolver = new VersionFolderPathResolver(downloadFolder == null || !downloadFolder.HasValue ? _packageInstallDir.Value : downloadFolder.Value.Value); + string nupkgPath = pathResolver.GetPackageFilePath(packageId.ToString(), resolvedPackageVersion); Directory.CreateDirectory(Path.GetDirectoryName(nupkgPath)); + using FileStream destinationStream = File.Create(nupkgPath); bool success = await ExponentialRetry.ExecuteWithRetryOnFailure(async () => await resource.CopyNupkgToStreamAsync( packageId.ToString(), @@ -218,7 +214,10 @@ public async Task GetPackageUrl(PackageId packageId, SourceRepository repository = GetSourceRepository(source); if (repository.PackageSource.IsLocal) { - return Path.Combine(repository.PackageSource.Source, $"{packageId}.{resolvedPackageVersion}.nupkg"); + return Path.Combine( + repository.PackageSource.Source, + new VersionFolderPathResolver(repository.PackageSource.Source).GetPackageFileName(packageId.ToString(), resolvedPackageVersion) + ); } ServiceIndexResourceV3 serviceIndexResource = repository.GetResourceAsync().Result; @@ -307,9 +306,8 @@ await GetPackageMetadataAsync(packageId.ToString(), packageVersion, packagesSour return (source, packageVersion); } - private string GetNupkgUrl(string baseUri, PackageId id, NuGetVersion version) => - baseUri + id.ToString() + "/" + version.ToNormalizedString() + "/" + id.ToString() + - "." + version.ToNormalizedString() + ".nupkg"; + private string GetNupkgUrl(string baseUri, PackageId id, NuGetVersion version) => baseUri + id.ToString() + "/" + version.ToNormalizedString() + "/" + id.ToString() + + "." + version.ToNormalizedString().ToLowerInvariant() + ".nupkg"; internal IEnumerable FindAllFilesNeedExecutablePermission(IEnumerable files, string targetPath) diff --git a/src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs b/src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs index 5173997199a0..ed32b67bbdeb 100644 --- a/src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs +++ b/src/Cli/dotnet/ToolPackage/ToolPackageDownloader.cs @@ -107,11 +107,11 @@ public IToolPackage InstallPackage(PackageLocation packageLocation, PackageId pa } NuGetVersion packageVersion = nugetPackageDownloader.GetBestPackageVersionAsync(packageId, versionRange, packageSourceLocation).GetAwaiter().GetResult(); - rollbackDirectory = isGlobalTool ? toolDownloadDir.Value: Path.Combine(toolDownloadDir.Value, packageId.ToString(), packageVersion.ToString()); + rollbackDirectory = isGlobalTool ? toolDownloadDir.Value: new VersionFolderPathResolver(toolDownloadDir.Value).GetInstallPath(packageId.ToString(), packageVersion); if (isGlobalTool) { - NuGetv3LocalRepository nugetPackageRootDirectory = new(Path.Combine(_toolPackageStore.GetRootPackageDirectory(packageId).ToString().Trim('"'), packageVersion.ToString())); + NuGetv3LocalRepository nugetPackageRootDirectory = new(new VersionFolderPathResolver(_toolPackageStore.Root.Value).GetInstallPath(packageId.ToString(), packageVersion)); var globalPackage = nugetPackageRootDirectory.FindPackage(packageId.ToString(), packageVersion); if (globalPackage != null) @@ -303,7 +303,7 @@ private static async Task DownloadAndExtractPackage( } // Extract the package - var nupkgDir = Path.Combine(packagesRootPath, packageId.ToString(), version.ToString()); + var nupkgDir = new VersionFolderPathResolver(packagesRootPath).GetInstallPath(packageId.ToString(), version); await nugetPackageDownloader.ExtractPackageAsync(packagePath, new DirectoryPath(nupkgDir)); return version; diff --git a/src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs b/src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs index b9299943926e..fa6a0b35cb4d 100644 --- a/src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs +++ b/src/Cli/dotnet/ToolPackage/ToolPackageInstance.cs @@ -6,6 +6,7 @@ using Microsoft.DotNet.Tools; using Microsoft.Extensions.EnvironmentAbstractions; using NuGet.Frameworks; +using NuGet.Packaging; using NuGet.ProjectModel; using NuGet.Versioning; @@ -85,7 +86,8 @@ public ToolPackageInstance(PackageId id, _lockFile = new Lazy( () => new LockFileFormat().Read(assetsJsonParentDirectory.WithFile(AssetsFileName).Value)); - var toolsPackagePath = Path.Combine(PackageDirectory.Value, Id.ToString(), Version.ToNormalizedString(), "tools"); + var installPath = new VersionFolderPathResolver(PackageDirectory.Value).GetInstallPath(Id.ToString(), Version); + var toolsPackagePath = Path.Combine(installPath, "tools"); Frameworks = Directory.GetDirectories(toolsPackagePath) .Select(path => NuGetFramework.ParseFolder(Path.GetFileName(path))); } @@ -127,7 +129,7 @@ private FilePath LockFileRelativePathToFullFilePath(string lockFileRelativePath, return PackageDirectory .WithSubDirectories( Id.ToString(), - library.Version.ToNormalizedString()) + library.Version.ToNormalizedString().ToLowerInvariant()) .WithFile(lockFileRelativePath); } @@ -209,7 +211,7 @@ private ToolConfiguration DeserializeToolConfiguration(LockFileTargetLibrary lib PackageDirectory .WithSubDirectories( Id.ToString(), - library.Version.ToNormalizedString()) + library.Version.ToNormalizedString().ToLowerInvariant()) .WithFile(dotnetToolSettings.Path); var configuration = ToolConfigurationDeserializer.Deserialize(toolConfigurationPath.Value); diff --git a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs b/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs index 98263a0c4fc7..d8ee2b421303 100644 --- a/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs +++ b/src/Cli/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs @@ -38,7 +38,7 @@ internal static class AddPackageParser var allowPrerelease = context.ParseResult.GetValue(PrereleaseOption); return QueryVersionsForPackage(packageId, context.WordToComplete, allowPrerelease, CancellationToken.None) .Result - .Select(version => new CompletionItem(version.ToNormalizedString())); + .Select(version => new CompletionItem(version.ToNormalizedString().ToLowerInvariant())); } else { diff --git a/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Mocks/MockPackageResolver.cs b/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Mocks/MockPackageResolver.cs index 94ea855dd214..622e12a1967c 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Mocks/MockPackageResolver.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Mocks/MockPackageResolver.cs @@ -22,7 +22,7 @@ public string GetPackageDirectory(string packageId, NuGetVersion version) public string GetPackageDirectory(string packageId, NuGetVersion version, out string packageRoot) { packageRoot = _root; - return Path.Combine(_root, packageId, version.ToNormalizedString(), "path"); + return Path.Combine(_root, packageId, version.ToNormalizedString().ToLowerInvariant(), "path"); } public string ResolvePackageAssetPath(LockFileTargetLibrary package, string relativePath) => Path.Combine(GetPackageDirectory(package.Name, package.Version), relativePath);