Skip to content

Commit

Permalink
fix: use reflection to find already imported libs GlitchEnzo#395
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-moss committed Dec 21, 2021
1 parent 0057044 commit 4e80f82
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions Assets/NuGet/Editor/NugetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,11 @@ private static bool IsAlreadyImportedInEngine(NugetPackageIdentifier package)
private static HashSet<string> alreadyImportedLibs = null;
private static HashSet<string> GetAlreadyImportedLibs()
{

if (alreadyImportedLibs == null)
{
string[] lookupPaths = GetAllLookupPaths();
IEnumerable<string> libNames = lookupPaths
.SelectMany(directory => Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories))
.Select(Path.GetFileName)
IEnumerable<string> libNames = AppDomain.CurrentDomain.GetAssemblies()
.Select(a => a.ManifestModule.Name)
.Select(p => Path.ChangeExtension(p, null));
alreadyImportedLibs = new HashSet<string>(libNames);
LogVerbose("Already imported libs: {0}", string.Join(", ", alreadyImportedLibs));
Expand All @@ -568,29 +567,6 @@ private static HashSet<string> 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
Expand Down

0 comments on commit 4e80f82

Please sign in to comment.