| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using Abp.Reflection.Extensions;
- namespace VberAdmin.Web;
- /// <summary>
- /// This class is used to find root path of the web project in;
- /// unit tests (to find views) and entity framework core command line commands (to find conn string).
- /// </summary>
- public static class WebContentDirectoryFinder
- {
- /// <summary>
- /// 获取 WebMvc/WebHost 根目录
- /// </summary>
- /// <returns></returns>
- /// <exception cref="Exception"></exception>
- public static string CalculateContentRootFolder()
- {
- var coreAssemblyDirectoryPath = Path.GetDirectoryName(typeof(VberAdminCoreModule).GetAssembly().Location);
- if (coreAssemblyDirectoryPath == null)
- {
- throw new Exception("Could not find location of VberAdmin.Core assembly!");
- }
- var directoryInfo = new DirectoryInfo(coreAssemblyDirectoryPath);
- while (!DirectoryContains(directoryInfo.FullName, "VberAdmin_V4.0.1_2022.sln"))
- {
- directoryInfo = directoryInfo.Parent ?? throw new Exception("Could not find content root folder!");
- }
- var webMvcFolder = Path.Combine(directoryInfo.FullName, "src", "VberAdmin.Web.Mvc");
- if (Directory.Exists(webMvcFolder))
- {
- return webMvcFolder;
- }
- var webHostFolder = Path.Combine(directoryInfo.FullName, "src", "VberAdmin.Web.Host");
- if (Directory.Exists(webHostFolder))
- {
- return webHostFolder;
- }
- throw new Exception("Could not find root folder of the web project!");
- }
- private static bool DirectoryContains(string directory, string fileName)
- {
- return Directory.GetFiles(directory).Any(filePath => string.Equals(Path.GetFileName(filePath), fileName));
- }
- }
|