Skip to content

Commit

Permalink
Merge pull request #351 from Particular/xunit-generation
Browse files Browse the repository at this point in the history
Use the same location detection as core
  • Loading branch information
WilliamBZA authored Jul 23, 2019
2 parents 1577a8d + ed45834 commit 8eee2d4
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/SqlPersistence/ScriptLocation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.IO;
using System.Reflection;
using NServiceBus;
using NServiceBus.Settings;

Expand All @@ -10,30 +9,20 @@ static class ScriptLocation

public static string FindScriptDirectory(ReadOnlySettings settings)
{
var currentDirectory = GetCurrentDirectory(settings);
var currentDirectory = GetScriptsRootPath(settings);
return Path.Combine(currentDirectory, ScriptFolder, settings.GetSqlDialect().Name);
}

static string GetCurrentDirectory(ReadOnlySettings settings)
static string GetScriptsRootPath(ReadOnlySettings settings)
{
if (settings.TryGet("SqlPersistence.ScriptDirectory", out string scriptDirectory))
{
return scriptDirectory;
}
var entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly == null)
{
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
var scriptDir = Path.Combine(baseDir, ScriptFolder);
//if the app domain base dir contains the scripts folder, return it. Otherwise add "bin" to the base dir so that web apps work correctly
if (Directory.Exists(scriptDir))
{
return baseDir;
}
return Path.Combine(baseDir, "bin");
}
var codeBase = entryAssembly.CodeBase;
return Directory.GetParent(new Uri(codeBase).LocalPath).FullName;

//NOTE: This is the same logic that Core uses for finding assembly scanning path.
// RelativeSearchPath is set for ASP .NET and points to the binaries folder i.e. /bin
return AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
}

public static void ValidateScriptExists(string createScript)
Expand Down

0 comments on commit 8eee2d4

Please sign in to comment.