|
|
@ -13,21 +13,32 @@ namespace MyCompanyName.MyProjectName |
|
|
{ |
|
|
{ |
|
|
public static string CalculateContentRootFolder() |
|
|
public static string CalculateContentRootFolder() |
|
|
{ |
|
|
{ |
|
|
var domainAssemblyDirectoryPath = Path.GetDirectoryName(typeof(MyProjectNameDomainModule).Assembly.Location); |
|
|
var domainAssemblyDirectoryPath = |
|
|
|
|
|
Path.GetDirectoryName(typeof(MyProjectNameDomainModule).Assembly.Location); |
|
|
if (domainAssemblyDirectoryPath == null) |
|
|
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); |
|
|
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"); |
|
|
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!"); |
|
|
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)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|