Skip to content

Commit

Permalink
Merge pull request #11912 from mrlacey/i11911-EmptyPaths
Browse files Browse the repository at this point in the history
fix: XAML Hot reload mishandling empty paths
  • Loading branch information
jeromelaban authored Apr 6, 2023
2 parents 6d239d9 + 11892b6 commit b3dc305
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,18 @@ private static void BuildProjectConfiguration(GeneratorExecutionContext context,
private static void BuildLibrarySearchPath(GeneratorExecutionContext context, IndentedStringBuilder sb)
{
var xamlPaths = EnumerateLocalSearchPaths(context);
var distictPaths = string.Join(Path.PathSeparator.ToString(), xamlPaths);

sb.AppendLineIndented($"""
[assembly: global::System.Reflection.AssemblyMetadata(
"{LibraryXamlSearchPathAssemblyMetadata}",
@"{distictPaths}"
)]
""");

if (xamlPaths.Any())
{
var distictPaths = string.Join(Path.PathSeparator.ToString(), xamlPaths);

sb.AppendLineIndented($"""
[assembly: global::System.Reflection.AssemblyMetadata(
"{LibraryXamlSearchPathAssemblyMetadata}",
@"{distictPaths}"
)]
""");
}
}

private static IEnumerable<string> EnumerateLibrarySearchPaths(GeneratorExecutionContext context)
Expand All @@ -150,7 +154,7 @@ private static IEnumerable<string> EnumerateLibrarySearchPaths(GeneratorExecutio

if (rawPaths is not null)
{
foreach (var path in rawPaths.Split(Path.PathSeparator))
foreach (var path in rawPaths.Split(new[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries))
{
yield return path;
}
Expand All @@ -176,7 +180,7 @@ IEnumerable<string> BuildSearchPath(string s)
var xamlPaths = from item in sources.SelectMany(BuildSearchPath)
select Path.GetDirectoryName(item);

return xamlPaths.Distinct();
return xamlPaths.Distinct().Where(x => !string.IsNullOrEmpty(x));
}

private static void BuildEndPointAttribute(GeneratorExecutionContext context, IndentedStringBuilder sb)
Expand Down

0 comments on commit b3dc305

Please sign in to comment.