Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Luo <basehello@icloud.com>2021-01-29 11:55:38 +0300
committerXiao Luo <basehello@icloud.com>2021-01-29 11:55:38 +0300
commit52dd21b8b0995f41226c33aef69f5d90b2ce3ddc (patch)
treef679f969b746409447b0ebec0c5efdda3b7cc886 /mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs
parent37ae438b80fa2b6e0c9518605c452e653a316006 (diff)
Remove the .NET Core platform assemblies in the external\Test folder. Add .NET Core platform assemblies from the installation path of the .NET Core by the custom DefaultAssemblyResolver for WSL, macOS, and Ubuntu OS environment.
Diffstat (limited to 'mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs')
-rw-r--r--mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs94
1 files changed, 94 insertions, 0 deletions
diff --git a/mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs b/mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs
new file mode 100644
index 00000000..f22f0702
--- /dev/null
+++ b/mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs
@@ -0,0 +1,94 @@
+using Mono.Cecil;
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace mdoc.Test
+{
+ // Fix DefaultAssemblyResolver don't load .NET Core Assemblies in macOS, WSL, and Ubuntu OS environment.
+ public class DotnetCoreAssemblyResolver : DefaultAssemblyResolver
+ {
+ public DotnetCoreAssemblyResolver()
+ {
+ AddDotnetCoreSearchDirectory();
+ }
+
+ private void AddDotnetCoreSearchDirectory()
+ {
+ if (Environment.OSVersion.Platform == PlatformID.Unix ||
+ Environment.OSVersion.Platform == PlatformID.MacOSX)
+ {
+ foreach (var item in GetDotnetCorePlatformAssembliesPath())
+ {
+ AddSearchDirectory(item);
+ }
+ }
+ }
+
+ private IEnumerable<string> GetDotnetCorePlatformAssembliesPath()
+ {
+ foreach (var installedSdkVersion in GetInstalledSdkVersions())
+ {
+ if (File.Exists(Path.Combine(installedSdkVersion, "System.dll")))
+ {
+ yield return installedSdkVersion;
+ }
+ }
+ }
+
+ private string[] GetInstalledSdkVersions()
+ {
+ var dotnetCorePackagesPath = GetDotnetCorePath();
+ if (Directory.Exists(dotnetCorePackagesPath))
+ {
+ return Directory.GetDirectories(dotnetCorePackagesPath);
+ }
+
+ return Array.Empty<string>();
+ }
+
+ private static string GetDotnetCorePath()
+ {
+ var dotnetCorePath = GetMacOSDotnetCorePath();
+ if (string.IsNullOrEmpty(dotnetCorePath))
+ {
+ dotnetCorePath = GetLinuxDotnetCorePath();
+ }
+
+ if (!Directory.Exists(dotnetCorePath))
+ {
+ throw new DirectoryNotFoundException($"The path of .NET Core was not found, do you have .NET Core installed? {dotnetCorePath}");
+ }
+
+ return dotnetCorePath;
+ }
+
+ private static string GetMacOSDotnetCorePath()
+ {
+ var macOSDotnetCorePath = GetAzureMacOSDotnetCorePath();
+ if (string.IsNullOrEmpty(macOSDotnetCorePath))
+ {
+ // Hard code the path of .NET Core for macOS.
+ macOSDotnetCorePath = "/usr/local/share/dotnet/shared/Microsoft.NETCore.App";
+ }
+
+ return Directory.Exists(macOSDotnetCorePath) ? macOSDotnetCorePath : string.Empty;
+ }
+
+ private static string GetAzureMacOSDotnetCorePath()
+ {
+ var azureMacOSDotnetCorePath = Environment.GetEnvironmentVariable("DOTNET_ROOT");
+ if (!string.IsNullOrEmpty(azureMacOSDotnetCorePath))
+ {
+ return Path.Combine(azureMacOSDotnetCorePath, "shared/Microsoft.NETCore.App");
+ }
+
+ return string.Empty;
+ }
+
+ private static string GetLinuxDotnetCorePath()
+ {
+ return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "dotnet/shared/Microsoft.NETCore.App");
+ }
+ }
+}