Merge pull request #9336 from abpframework/liangshiwei/ncrunch

Supported NCrunch
pull/9350/head
Halil İbrahim Kalkan 4 years ago committed by GitHub
commit 0aaaea9528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,21 +13,32 @@ namespace MyCompanyName.MyProjectName
{
public static string CalculateContentRootFolder()
{
var domainAssemblyDirectoryPath = Path.GetDirectoryName(typeof(MyProjectNameDomainModule).Assembly.Location);
var domainAssemblyDirectoryPath =
Path.GetDirectoryName(typeof(MyProjectNameDomainModule).Assembly.Location);
if (domainAssemblyDirectoryPath == null)
{
throw new Exception($"Could not find location of {typeof(MyProjectNameDomainModule).Assembly.FullName} assembly!");
throw new Exception(
$"Could not find location of {typeof(MyProjectNameDomainModule).Assembly.FullName} assembly!");
}
var directoryInfo = new DirectoryInfo(domainAssemblyDirectoryPath);
while (!DirectoryContains(directoryInfo.FullName, "MyCompanyName.MyProjectName.sln"))
if (Environment.GetEnvironmentVariable("NCrunch") == "1")
{
if (directoryInfo.Parent == null)
while (!DirectoryContains(directoryInfo.FullName, "MyCompanyName.MyProjectName.Web.csproj", SearchOption.AllDirectories))
{
throw new Exception("Could not find content root folder!");
directoryInfo = directoryInfo.Parent ?? throw new Exception("Could not find content root folder!");
}
directoryInfo = directoryInfo.Parent;
var webProject = Directory.GetFiles(directoryInfo.FullName, string.Empty, SearchOption.AllDirectories)
.First(filePath => string.Equals(Path.GetFileName(filePath), "MyCompanyName.MyProjectName.Web.csproj"));
return Path.GetDirectoryName(webProject);
}
while (!DirectoryContains(directoryInfo.FullName, "MyCompanyName.MyProjectName.sln"))
{
directoryInfo = directoryInfo.Parent ?? throw new Exception("Could not find content root folder!");
}
var webFolder = Path.Combine(directoryInfo.FullName, $"src{Path.DirectorySeparatorChar}MyCompanyName.MyProjectName.Web");
@ -39,9 +50,11 @@ namespace MyCompanyName.MyProjectName
throw new Exception("Could not find root folder of the web project!");
}
private static bool DirectoryContains(string directory, string fileName)
private static bool DirectoryContains(string directory, string fileName,
SearchOption searchOption = SearchOption.TopDirectoryOnly)
{
return Directory.GetFiles(directory).Any(filePath => string.Equals(Path.GetFileName(filePath), fileName));
return Directory.GetFiles(directory, string.Empty, searchOption)
.Any(filePath => string.Equals(Path.GetFileName(filePath), fileName));
}
}
}

Loading…
Cancel
Save