diff --git a/Assets/NuGet/Editor/NugetHelper.cs b/Assets/NuGet/Editor/NugetHelper.cs index 3326a249..efecab1f 100644 --- a/Assets/NuGet/Editor/NugetHelper.cs +++ b/Assets/NuGet/Editor/NugetHelper.cs @@ -554,12 +554,11 @@ private static bool IsAlreadyImportedInEngine(NugetPackageIdentifier package) private static HashSet alreadyImportedLibs = null; private static HashSet GetAlreadyImportedLibs() { + if (alreadyImportedLibs == null) { - string[] lookupPaths = GetAllLookupPaths(); - IEnumerable libNames = lookupPaths - .SelectMany(directory => Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories)) - .Select(Path.GetFileName) + IEnumerable libNames = AppDomain.CurrentDomain.GetAssemblies() + .Select(a => a.ManifestModule.Name) .Select(p => Path.ChangeExtension(p, null)); alreadyImportedLibs = new HashSet(libNames); LogVerbose("Already imported libs: {0}", string.Join(", ", alreadyImportedLibs)); @@ -568,29 +567,6 @@ private static HashSet GetAlreadyImportedLibs() return alreadyImportedLibs; } - private static string[] GetAllLookupPaths() - { - var executablePath = EditorApplication.applicationPath; - var roots = new[] { - // MacOS directory layout - Path.Combine(executablePath, "Contents"), - // Windows directory layout - Path.Combine(Directory.GetParent(executablePath).FullName, "Data") - }; - var relativePaths = new[] { - Path.Combine("NetStandard", "compat"), - Path.Combine("MonoBleedingEdge", "lib", "mono") - }; - var allPossiblePaths = roots - .SelectMany(root => relativePaths - .Select(relativePath => Path.Combine(root, relativePath))); - var existingPaths = allPossiblePaths - .Where(Directory.Exists) - .ToArray(); - LogVerbose("All existing path to dependency lookup are: {0}", string.Join(", ", existingPaths)); - return existingPaths; - } - public static NugetFrameworkGroup GetBestDependencyFrameworkGroupForCurrentSettings(NugetPackage package) { var targetFrameworks = package.Dependencies diff --git a/Assets/Tests/Editor/NuGetTests.cs b/Assets/Tests/Editor/NuGetTests.cs index 851aece1..ea36f5c2 100644 --- a/Assets/Tests/Editor/NuGetTests.cs +++ b/Assets/Tests/Editor/NuGetTests.cs @@ -190,4 +190,27 @@ public void VersionOutOfRangeTest(string versionRange, string version) Assert.IsFalse(id.InRange(version), "{0} WAS in range of {1}!", version, versionRange); } + + /// + /// Dependencies under MonoBleedingEdge may not be part of Unity Editor/Runtime, lets test the + /// by checking the status of MonoBleedingEdge only DLLs and + /// those that are also part of Unity Runtime. + /// + [Test] + [TestCase("System.ComponentModel.Annotations", "5.0.0", false)] + [TestCase("Mono.Posix", "7.1.0-final.1.21458.1", true)] + public void MonoBleedingEdgeTest(string id, string version, bool alreadyInstalled) + { + var identifier = new NugetPackageIdentifier(id, version); + if (alreadyInstalled) + { + Assert.IsTrue(NugetHelper.IsInstalled(identifier), "The package should be installed: {0} {1}", identifier.Id, + identifier.Version); + } + else + { + Assert.IsFalse(NugetHelper.IsInstalled(identifier), "The package should not be installed: {0} {1}", identifier.Id, + identifier.Version); + } + } }