Skip to content

Commit c30fe28

Browse files
Workaround: IDEs use a different current directory than dotnet run
1 parent 6d84dad commit c30fe28

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

generators.new/Paths.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Generators;
22

33
internal static class Paths
44
{
5-
private static readonly string RootDir = Path.GetFullPath(Path.Join(Environment.CurrentDirectory, "..", "..", "..", ".."));
5+
private static readonly string RootDir = GetRootDir();
66
private static readonly string ProbSpecsExercisesDir = Path.Join(RootDir, ".problem-specifications", "exercises");
77
internal static readonly string PracticeExercisesDir = Path.Join(RootDir, "exercises", "practice");
88

@@ -11,4 +11,14 @@ internal static class Paths
1111
internal static string TestsTomlFile(Exercise exercise) => Path.Join(ExerciseDir(exercise), ".meta", "tests.toml");
1212
internal static string TemplateFile(Exercise exercise) => Path.Join(ExerciseDir(exercise), ".meta", "Generator.tpl");
1313
internal static string CanonicalDataFile(Exercise exercise) => Path.Join(ProbSpecsExercisesDir, exercise.Slug, "canonical-data.json");
14+
15+
private static string GetRootDir()
16+
{
17+
// Workaround: IDEs use a different current directory than dotnet run
18+
var currentDir = Environment.CurrentDirectory;
19+
while (!File.Exists(Path.Join(currentDir, "LICENSE")))
20+
currentDir = Path.GetDirectoryName(currentDir);
21+
22+
return currentDir!;
23+
}
1424
}

0 commit comments

Comments
 (0)