This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ResolverUtils.cs
50 lines (45 loc) · 1.76 KB
/
ResolverUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 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.
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.Extensions.DependencyModel.Resolution
{
internal static class ResolverUtils
{
internal static bool TryResolvePackagePath(IFileSystem fileSystem, CompilationLibrary library, string basePath, out string packagePath)
{
packagePath = Path.Combine(
basePath,
library.Name.ToLowerInvariant(),
library.Version.ToLowerInvariant());
if (fileSystem.Directory.Exists(packagePath))
{
return true;
}
return false;
}
internal static IEnumerable<string> ResolveFromPackagePath(IFileSystem fileSystem, CompilationLibrary library, string basePath)
{
foreach (var assembly in library.Assemblies)
{
string fullName;
if (!TryResolveAssemblyFile(fileSystem, basePath, assembly, out fullName))
{
throw new InvalidOperationException($"Can not find assembly file for package {library.Name} at '{fullName}'");
}
yield return fullName;
}
}
internal static bool TryResolveAssemblyFile(IFileSystem fileSystem, string basePath, string assemblyPath, out string fullName)
{
fullName = Path.Combine(basePath, assemblyPath);
if (fileSystem.File.Exists(fullName))
{
return true;
}
return false;
}
}
}