From 8cc568bf3134d05c628dcf7ed535653e13f8082f Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 26 Jul 2016 13:20:23 -0500 Subject: [PATCH] Fix package code for new NuGet. The new NuGet uses tolower paths, and we need to react to it. Port https://github.com/dotnet/cli/pull/2722 Port https://github.com/dotnet/cli/pull/3554 --- .../ExportFiles/valid/project.lock.json | 4 ++ .../Executable.cs | 16 +++++-- .../NuGetCacheSentinel.cs | 4 +- .../Graph/LockFile.cs | 1 + .../Graph/LockFilePackageFolder.cs | 10 +++++ .../Graph/LockFileReader.cs | 15 +++++++ .../ProjectContextBuilder.cs | 30 +++++++++++-- .../Resolution/PackageDependencyProvider.cs | 45 +++++-------------- .../project.json | 1 + ...PackageCacheCompilationAssemblyResolver.cs | 3 +- .../Resolution/ResolverUtils.cs | 6 ++- src/dotnet-compile-fsc/Program.cs | 3 +- src/dotnet/commands/dotnet-run/RunCommand.cs | 15 ++++--- .../LockFilePatchingTests.cs | 11 +++++ .../PackageDependencyProviderTests.cs | 7 +-- .../PackageCacheResolverTest.cs | 26 +++++++---- .../PackageResolverTest.cs | 20 ++++++--- ...tTheUserIsRunningDotNetForTheFirstTime.cs} | 2 +- 18 files changed, 148 insertions(+), 71 deletions(-) create mode 100644 src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageFolder.cs rename test/dotnet.Tests/{GivenThatTheUserIsRunningDoNetForTheFirstTime.cs => GivenThatTheUserIsRunningDotNetForTheFirstTime.cs} (97%) diff --git a/TestAssets/LockFiles/ExportFiles/valid/project.lock.json b/TestAssets/LockFiles/ExportFiles/valid/project.lock.json index 244c3771bc9..099c3246c5a 100644 --- a/TestAssets/LockFiles/ExportFiles/valid/project.lock.json +++ b/TestAssets/LockFiles/ExportFiles/valid/project.lock.json @@ -57,5 +57,9 @@ "ClassLibrary2", "ClassLibrary3" ] + }, + "packageFolders": { + "/foo/packages": {}, + "/foo/packages2": {} } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.Compiler.Common/Executable.cs b/src/Microsoft.DotNet.Compiler.Common/Executable.cs index 52ebbe924f5..d3904063a16 100644 --- a/src/Microsoft.DotNet.Compiler.Common/Executable.cs +++ b/src/Microsoft.DotNet.Compiler.Common/Executable.cs @@ -67,7 +67,7 @@ private void VerifyCoreClrPresenceInPackageGraph() .Any(); // coreclr should be present for standalone apps - if (! isCoreClrPresent) + if (!isCoreClrPresent) { throw new InvalidOperationException("Expected coreclr library not found in package graph. Please try running dotnet restore again."); } @@ -94,7 +94,7 @@ private void MakeCompilationOutputRunnableForFullFramework() } private void MakeCompilationOutputRunnableForCoreCLR() - { + { WriteDepsFileAndCopyProjectDependencies(_exporter); var emitEntryPoint = _compilerOptions.EmitEntryPoint ?? false; @@ -275,8 +275,16 @@ private void WriteDevRuntimeConfig() private void AddAdditionalProbingPaths(JObject runtimeOptions) { - var additionalProbingPaths = new JArray(_context.PackagesDirectory); - runtimeOptions.Add("additionalProbingPaths", additionalProbingPaths); + if (_context.LockFile != null) + { + var additionalProbingPaths = new JArray(); + foreach (var packageFolder in _context.LockFile.PackageFolders) + { + additionalProbingPaths.Add(packageFolder.Path); + } + + runtimeOptions.Add("additionalProbingPaths", additionalProbingPaths); + } } public void WriteDeps(IEnumerable runtimeExports, IEnumerable compilationExports) diff --git a/src/Microsoft.DotNet.Configurer/NuGetCacheSentinel.cs b/src/Microsoft.DotNet.Configurer/NuGetCacheSentinel.cs index a24a5441826..a0feea8275b 100644 --- a/src/Microsoft.DotNet.Configurer/NuGetCacheSentinel.cs +++ b/src/Microsoft.DotNet.Configurer/NuGetCacheSentinel.cs @@ -4,7 +4,7 @@ using System.IO; using Microsoft.DotNet.Cli.Utils; using Microsoft.Extensions.EnvironmentAbstractions; -using Microsoft.DotNet.ProjectModel.Resolution; +using NuGet.Configuration; namespace Microsoft.DotNet.Configurer { @@ -23,7 +23,7 @@ private string NuGetCachePath { if (string.IsNullOrEmpty(_nugetCachePath)) { - _nugetCachePath = PackageDependencyProvider.ResolvePackagesPath(null, null); + _nugetCachePath = NuGetPathContext.Create(new NullSettings()).UserPackageFolder; } return _nugetCachePath; diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFile.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFile.cs index 9f9db6459d0..ab3355426ab 100644 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFile.cs +++ b/src/Microsoft.DotNet.ProjectModel/Graph/LockFile.cs @@ -20,6 +20,7 @@ public class LockFile public IList ProjectLibraries { get; set; } = new List(); public IList Targets { get; set; } = new List(); public ExportFile ExportFile { get; set; } + public IList PackageFolders { get; set; } = new List(); public LockFile(string lockFilePath) { diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageFolder.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageFolder.cs new file mode 100644 index 00000000000..fc77a453fcb --- /dev/null +++ b/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageFolder.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.DotNet.ProjectModel.Graph +{ + public class LockFilePackageFolder + { + public string Path { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileReader.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileReader.cs index 9d7a070e3f1..eff31f5096c 100644 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileReader.cs +++ b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileReader.cs @@ -117,6 +117,7 @@ private LockFile ReadLockFile(string lockFilePath, JObject cursor) lockFile.Targets = ReadObject(cursor.Value("targets"), ReadTarget); lockFile.ProjectFileDependencyGroups = ReadObject(cursor.Value("projectFileDependencyGroups"), ReadProjectFileDependencyGroup); ReadLibrary(cursor.Value("libraries"), lockFile); + lockFile.PackageFolders = ReadObject(cursor.Value("packageFolders"), ReadPackageFolder); return lockFile; } @@ -194,6 +195,20 @@ private LockFileTarget ReadTarget(string property, JToken json) return target; } + private LockFilePackageFolder ReadPackageFolder(string property, JToken json) + { + var jobject = json as JObject; + if (jobject == null) + { + throw FileFormatException.Create("The value type is not an object.", json); + } + + var packageFolder = new LockFilePackageFolder(); + packageFolder.Path = property; + + return packageFolder; + } + private LockFileTargetLibrary ReadTargetLibrary(string property, JToken json) { var jobject = json as JObject; diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs index 3a182eb034b..2839eb06ecf 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs @@ -3,14 +3,14 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; -using System.Reflection; using System.Text; using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resolution; +using NuGet.Common; +using NuGet.Configuration; using NuGet.Frameworks; namespace Microsoft.DotNet.ProjectModel @@ -210,7 +210,6 @@ public ProjectContext Build() } RootDirectory = globalSettings?.DirectoryPath ?? RootDirectory; - PackagesDirectory = PackagesDirectory ?? PackageDependencyProvider.ResolvePackagesPath(RootDirectory, globalSettings); FrameworkReferenceResolver frameworkReferenceResolver; if (string.IsNullOrEmpty(ReferenceAssembliesPath)) @@ -228,6 +227,17 @@ public ProjectContext Build() ReadLockFile(diagnostics); + // some callers only give ProjectContextBuilder a LockFile + ProjectDirectory = ProjectDirectory ?? TryGetProjectDirectoryFromLockFile(); + + INuGetPathContext nugetPathContext = null; + if (ProjectDirectory != null) + { + nugetPathContext = NuGetPathContext.Create(ProjectDirectory); + } + + PackagesDirectory = PackagesDirectory ?? nugetPathContext?.UserPackageFolder; + var validLockFile = true; string lockFileValidationMessage = null; @@ -271,7 +281,7 @@ public ProjectContext Build() target = SelectTarget(LockFile, isPortable); if (target != null) { - var nugetPackageResolver = new PackageDependencyProvider(PackagesDirectory, frameworkReferenceResolver); + var nugetPackageResolver = new PackageDependencyProvider(nugetPathContext, frameworkReferenceResolver); var msbuildProjectResolver = new MSBuildDependencyProvider(Project, ProjectResolver); ScanLibraries(target, lockFileLookup, libraries, msbuildProjectResolver, nugetPackageResolver, projectResolver); @@ -377,6 +387,18 @@ public ProjectContext Build() diagnostics); } + private string TryGetProjectDirectoryFromLockFile() + { + string result = null; + + if (LockFile != null && !string.IsNullOrEmpty(LockFile.LockFilePath)) + { + result = Path.GetDirectoryName(LockFile.LockFilePath); + } + + return result; + } + private void ReadLockFile(ICollection diagnostics) { try diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs index df0bdf64f2b..f48feb5828e 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs @@ -8,6 +8,7 @@ using System.Reflection.Metadata; using System.Reflection.PortableExecutable; using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.Common; using NuGet.Frameworks; using NuGet.Packaging; @@ -15,12 +16,16 @@ namespace Microsoft.DotNet.ProjectModel.Resolution { public class PackageDependencyProvider { - private readonly VersionFolderPathResolver _packagePathResolver; + private readonly FallbackPackagePathResolver _packagePathResolver; private readonly FrameworkReferenceResolver _frameworkReferenceResolver; - public PackageDependencyProvider(string packagesPath, FrameworkReferenceResolver frameworkReferenceResolver) + public PackageDependencyProvider(INuGetPathContext nugetPathContext, FrameworkReferenceResolver frameworkReferenceResolver) { - _packagePathResolver = new VersionFolderPathResolver(packagesPath); + if (nugetPathContext != null) + { + _packagePathResolver = new FallbackPackagePathResolver(nugetPathContext); + } + _frameworkReferenceResolver = frameworkReferenceResolver; } @@ -40,8 +45,8 @@ public PackageDescription GetDescription(NuGetFramework targetFramework, LockFil var dependencies = new List(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count); PopulateDependencies(dependencies, targetLibrary, targetFramework); - var path = _packagePathResolver.GetInstallPath(package.Name, package.Version); - var exists = Directory.Exists(path); + var path = _packagePathResolver?.GetPackageDirectory(package.Name, package.Version); + bool exists = path != null; if (exists) { @@ -155,35 +160,5 @@ public static bool IsPlaceholderFile(string path) { return string.Equals(Path.GetFileName(path), "_._", StringComparison.Ordinal); } - - public static string ResolvePackagesPath(string rootDirectory, GlobalSettings settings) - { - // Order - // 1. global.json { "packages": "..." } - // 2. EnvironmentNames.PackagesStore environment variable - // 3. NuGet.config repositoryPath (maybe)? - // 4. {DefaultLocalRuntimeHomeDir}\packages - - if (!string.IsNullOrEmpty(settings?.PackagesPath)) - { - return Path.Combine(rootDirectory, settings.PackagesPath); - } - - var runtimePackages = Environment.GetEnvironmentVariable(EnvironmentNames.PackagesStore); - - if (!string.IsNullOrEmpty(runtimePackages)) - { - return runtimePackages; - } - - var profileDirectory = Environment.GetEnvironmentVariable("USERPROFILE"); - - if (string.IsNullOrEmpty(profileDirectory)) - { - profileDirectory = Environment.GetEnvironmentVariable("HOME"); - } - - return Path.Combine(profileDirectory, ".nuget", "packages"); - } } } diff --git a/src/Microsoft.DotNet.ProjectModel/project.json b/src/Microsoft.DotNet.ProjectModel/project.json index 5a0ae4ffe96..018b321013b 100644 --- a/src/Microsoft.DotNet.ProjectModel/project.json +++ b/src/Microsoft.DotNet.ProjectModel/project.json @@ -9,6 +9,7 @@ "target": "project" }, "Newtonsoft.Json": "9.0.1", + "NuGet.Configuration": "3.5.0-rc1-final", "NuGet.Packaging": "3.5.0-rc1-final", "NuGet.RuntimeModel": "3.5.0-rc1-final", "System.Reflection.Metadata": "1.4.1" diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCacheCompilationAssemblyResolver.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCacheCompilationAssemblyResolver.cs index 156ea0622b2..7497f0e0876 100644 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCacheCompilationAssemblyResolver.cs +++ b/src/Microsoft.Extensions.DependencyModel/Resolution/PackageCacheCompilationAssemblyResolver.cs @@ -53,7 +53,8 @@ public bool TryResolveAssemblyPaths(CompilationLibrary library, List ass if (ResolverUtils.TryResolvePackagePath(_fileSystem, library, _packageCacheDirectory, out packagePath)) { var hashAlgorithm = library.Hash.Substring(0, hashSplitterPos); - var cacheHashPath = Path.Combine(packagePath, $"{library.Name}.{library.Version}.nupkg.{hashAlgorithm}"); + var cacheHashFileName = $"{library.Name.ToLowerInvariant()}.{library.Version.ToLowerInvariant()}.nupkg.{hashAlgorithm}"; + var cacheHashPath = Path.Combine(packagePath, cacheHashFileName); if (_fileSystem.File.Exists(cacheHashPath) && _fileSystem.File.ReadAllText(cacheHashPath) == library.Hash.Substring(hashSplitterPos + 1)) diff --git a/src/Microsoft.Extensions.DependencyModel/Resolution/ResolverUtils.cs b/src/Microsoft.Extensions.DependencyModel/Resolution/ResolverUtils.cs index b9b93d2765c..e105ad8c59c 100644 --- a/src/Microsoft.Extensions.DependencyModel/Resolution/ResolverUtils.cs +++ b/src/Microsoft.Extensions.DependencyModel/Resolution/ResolverUtils.cs @@ -12,7 +12,11 @@ internal static class ResolverUtils { internal static bool TryResolvePackagePath(IFileSystem fileSystem, CompilationLibrary library, string basePath, out string packagePath) { - packagePath = Path.Combine(basePath, library.Name, library.Version); + packagePath = Path.Combine( + basePath, + library.Name.ToLowerInvariant(), + library.Version.ToLowerInvariant()); + if (fileSystem.Directory.Exists(packagePath)) { return true; diff --git a/src/dotnet-compile-fsc/Program.cs b/src/dotnet-compile-fsc/Program.cs index 76c8b351dbb..1eb619ab9fb 100644 --- a/src/dotnet-compile-fsc/Program.cs +++ b/src/dotnet-compile-fsc/Program.cs @@ -13,6 +13,7 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Resolution; +using NuGet.Configuration; namespace Microsoft.DotNet.Tools.Compiler.Fsc { @@ -296,7 +297,7 @@ private static Command RunFsc(List fscArgs, string temp) private static FscCommandSpec ResolveFsc(List fscArgs, string temp) { - var nugetPackagesRoot = PackageDependencyProvider.ResolvePackagesPath(null, null); + var nugetPackagesRoot = NuGetPathContext.Create(Directory.GetCurrentDirectory())?.UserPackageFolder; var depsFile = Path.Combine(AppContext.BaseDirectory, "dotnet-compile-fsc" + FileNameSuffixes.DepsJson); var depsJsonCommandResolver = new DepsJsonCommandResolver(nugetPackagesRoot); diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 4219a8847e9..e763e0704fe 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -145,13 +145,16 @@ private int RunExecutable() } List hostArgs = new List(); - if (!_context.TargetFramework.IsDesktop()) + if (!_context.TargetFramework.IsDesktop() && _context.LockFile != null) { - // Add Nuget Packages Probing Path - var nugetPackagesRoot = _context.PackagesDirectory; - var probingPathArg = "--additionalprobingpath"; - hostArgs.Insert(0, nugetPackagesRoot); - hostArgs.Insert(0, probingPathArg); + // Add Nuget Packages Probing Paths + const string probingPathArg = "--additionalprobingpath"; + + foreach (var packageFolder in _context.LockFile.PackageFolders) + { + hostArgs.Insert(0, packageFolder.Path); + hostArgs.Insert(0, probingPathArg); + } } // Now launch the output and give it the results diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs index fc1f1498cbe..759be0dc2a7 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs @@ -120,6 +120,17 @@ public void TestMissmatchingFileVersionsUnderDesignTime() Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true)); } + [Fact] + public void TestPackageFoldersLoadCorrectly() + { + var lockFilePath = GetLockFilePath("valid"); + var lockFile = LockFileReader.Read(lockFilePath, designTime: false); + + Assert.Equal(2, lockFile.PackageFolders.Count); + Assert.Equal("/foo/packages", lockFile.PackageFolders[0].Path); + Assert.Equal("/foo/packages2", lockFile.PackageFolders[1].Path); + } + private static int LibraryNumberFromName(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library) { var libraryName = library.Name; diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs index b2e58d8bb67..4a980e71fa5 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs @@ -3,6 +3,7 @@ using Microsoft.DotNet.ProjectModel.Resolution; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; +using NuGet.Configuration; using NuGet.Frameworks; using NuGet.Versioning; using Xunit; @@ -15,7 +16,7 @@ public class PackageDependencyProviderTests : TestBase [Fact] public void GetDescriptionShouldNotModifyTarget() { - var provider = new PackageDependencyProvider("/foo/packages", new FrameworkReferenceResolver("/foo/references")); + var provider = new PackageDependencyProvider(NuGetPathContext.Create("/foo/packages"), new FrameworkReferenceResolver("/foo/references")); var package = new LockFilePackageLibrary(); package.Name = "Something"; package.Version = NuGetVersion.Parse("1.0.0"); @@ -46,7 +47,7 @@ public void GetDescriptionShouldNotModifyTarget() [Fact] public void HasCompileTimePlaceholderChecksAllCompileTimeAssets() { - var provider = new PackageDependencyProvider("/foo/packages", new FrameworkReferenceResolver("/foo/references")); + var provider = new PackageDependencyProvider(NuGetPathContext.Create("/foo/packages"), new FrameworkReferenceResolver("/foo/references")); var package = new LockFilePackageLibrary(); package.Name = "Something"; package.Version = NuGetVersion.Parse("1.0.0"); @@ -74,7 +75,7 @@ public void HasCompileTimePlaceholderChecksAllCompileTimeAssets() [Fact] public void HasCompileTimePlaceholderReturnsFalseIfEmpty() { - var provider = new PackageDependencyProvider("/foo/packages", new FrameworkReferenceResolver("/foo/references")); + var provider = new PackageDependencyProvider(NuGetPathContext.Create("/foo/packages"), new FrameworkReferenceResolver("/foo/references")); var package = new LockFilePackageLibrary(); package.Name = "Something"; package.Version = NuGetVersion.Parse("1.0.0"); diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/PackageCacheResolverTest.cs b/test/Microsoft.Extensions.DependencyModel.Tests/PackageCacheResolverTest.cs index 7ea550b9804..91735cd6bb9 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/PackageCacheResolverTest.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/PackageCacheResolverTest.cs @@ -19,7 +19,7 @@ public class PackageCacheResolverTest [Fact] public void SholdUseEnvironmentVariableToGetDefaultLocation() { - var result = PackageCacheCompilationAssemblyResolver.GetDefaultPackageCacheDirectory(GetDefaultEnviroment()); + var result = PackageCacheCompilationAssemblyResolver.GetDefaultPackageCacheDirectory(GetDefaultEnvironment()); result.Should().Be(CachePath); } @@ -55,10 +55,10 @@ public void FailsOnInvalidHash(string hash) [Fact] public void ChecksHashFile() { - var packagePath = Path.Combine(CachePath, F.DefaultPackageName, F.DefaultVersion); + var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); var fileSystem = FileSystemMockBuilder.Create() .AddFile( - Path.Combine(packagePath, $"{F.DefaultPackageName}.{F.DefaultVersion}.nupkg.{F.DefaultHashAlgoritm}"), + GetHashFilePath(packagePath), "WRONGHASH" ) .AddFiles(packagePath, F.DefaultAssemblies) @@ -74,10 +74,10 @@ public void ChecksHashFile() [Fact] public void ResolvesAllAssemblies() { - var packagePath = Path.Combine(CachePath, F.DefaultPackageName, F.DefaultVersion); + var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); var fileSystem = FileSystemMockBuilder.Create() .AddFile( - Path.Combine(packagePath, $"{F.DefaultPackageName}.{F.DefaultVersion}.nupkg.{F.DefaultHashAlgoritm}"), + GetHashFilePath(packagePath), F.DefaultHashValue ) .AddFiles(packagePath, F.TwoAssemblies) @@ -98,10 +98,10 @@ public void ResolvesAllAssemblies() [Fact] public void FailsWhenOneOfAssembliesNotFound() { - var packagePath = Path.Combine(CachePath, F.DefaultPackageName, F.DefaultVersion); + var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); var fileSystem = FileSystemMockBuilder.Create() .AddFile( - Path.Combine(packagePath, $"{F.DefaultPackageName}.{F.DefaultVersion}.nupkg.{F.DefaultHashAlgoritm}"), + GetHashFilePath(packagePath), F.DefaultHashValue ) .AddFiles(packagePath, F.DefaultAssemblyPath) @@ -117,13 +117,23 @@ public void FailsWhenOneOfAssembliesNotFound() .And.Contain(library.Name); } - private IEnvironment GetDefaultEnviroment() + private IEnvironment GetDefaultEnvironment() { return EnvironmentMockBuilder.Create() .AddVariable("DOTNET_PACKAGES_CACHE", CachePath) .Build(); } + private static string GetPackagesPath(string id, string version) + { + return PackageResolverTest.GetPackagesPath(CachePath, id, version); + } + private static string GetHashFilePath(string packagePath) + { + return Path.Combine( + packagePath, + $"{F.DefaultPackageName.ToLowerInvariant()}.{F.DefaultVersion.ToLowerInvariant()}.nupkg.{F.DefaultHashAlgoritm}"); + } } } diff --git a/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs b/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs index c6727db7fad..dd69f512bd5 100644 --- a/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs +++ b/test/Microsoft.Extensions.DependencyModel.Tests/PackageResolverTest.cs @@ -17,7 +17,7 @@ public class PackageResolverTest private static string PackagesPath = Path.Combine("package", "directory", "location"); [Fact] - public void SholdUseEnvironmentVariableToGetDefaultLocation() + public void ShouldUseEnvironmentVariableToGetDefaultLocation() { var environment = EnvironmentMockBuilder.Create() .AddVariable("NUGET_PACKAGES", PackagesPath) @@ -29,7 +29,7 @@ public void SholdUseEnvironmentVariableToGetDefaultLocation() [Fact] - public void SholdUseNugetUnderUserProfileOnWindows() + public void ShouldUseNugetUnderUserProfileOnWindows() { var environment = EnvironmentMockBuilder.Create() .AddVariable("USERPROFILE", "User Profile") @@ -40,7 +40,7 @@ public void SholdUseNugetUnderUserProfileOnWindows() } [Fact] - public void SholdUseNugetUnderHomeOnNonWindows() + public void ShouldUseNugetUnderHomeOnNonWindows() { var environment = EnvironmentMockBuilder.Create() .AddVariable("HOME", "User Home") @@ -53,7 +53,7 @@ public void SholdUseNugetUnderHomeOnNonWindows() [Fact] public void ResolvesAllAssemblies() { - var packagePath = Path.Combine(PackagesPath, F.DefaultPackageName, F.DefaultVersion); + var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); var fileSystem = FileSystemMockBuilder.Create() .AddFiles(packagePath, F.TwoAssemblies) .Build(); @@ -73,7 +73,7 @@ public void ResolvesAllAssemblies() [Fact] public void FailsWhenOneOfAssembliesNotFound() { - var packagePath = Path.Combine(PackagesPath, F.DefaultPackageName, F.DefaultVersion); + var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion); var fileSystem = FileSystemMockBuilder.Create() .AddFiles(packagePath, F.DefaultAssemblyPath) .Build(); @@ -87,5 +87,15 @@ public void FailsWhenOneOfAssembliesNotFound() .Contain(F.SecondAssemblyPath) .And.Contain(library.Name); } + + private static string GetPackagesPath(string id, string version) + { + return GetPackagesPath(PackagesPath, id, version); + } + + internal static string GetPackagesPath(string basePath, string id, string version) + { + return Path.Combine(basePath, id.ToLowerInvariant(), version.ToLowerInvariant()); + } } } diff --git a/test/dotnet.Tests/GivenThatTheUserIsRunningDoNetForTheFirstTime.cs b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs similarity index 97% rename from test/dotnet.Tests/GivenThatTheUserIsRunningDoNetForTheFirstTime.cs rename to test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs index b2df620d2c3..4faf110c1d3 100644 --- a/test/dotnet.Tests/GivenThatTheUserIsRunningDoNetForTheFirstTime.cs +++ b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs @@ -76,7 +76,7 @@ public void It_restores_the_nuget_packages_to_the_nuget_cache_folder() [Fact] public void It_creates_a_sentinel_file_under_the_nuget_cache_folder() { - _nugetCacheFolder.Should().HaveDirectory("Microsoft.NETCore.App"); + _nugetCacheFolder.Should().HaveDirectory("microsoft.netcore.app"); } private string GetDotnetVersion()