Skip to content

Commit df91fa1

Browse files
Assembly.Location in bundled applications returns string.Empty, which breaks the current logic for probing the XML docs file location. (#1160)
This change uses AppContext.BaseDirectory to look for the XML docs for bundled apps. Fixes #1031
1 parent 002dd94 commit df91fa1

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/System.CommandLine.DragonFruit/CommandLine.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,26 @@ public static Option BuildOption(this ParameterDescriptor parameter)
311311

312312
private static string GetDefaultXmlDocsFileLocation(Assembly assembly)
313313
{
314-
return Path.Combine(
315-
Path.GetDirectoryName(assembly.Location),
316-
Path.GetFileNameWithoutExtension(assembly.Location) + ".xml");
314+
if (!string.IsNullOrEmpty(assembly.Location))
315+
{
316+
return Path.Combine(
317+
Path.GetDirectoryName(assembly.Location),
318+
Path.GetFileNameWithoutExtension(assembly.Location) + ".xml");
319+
}
320+
321+
// Assembly.Location is empty for bundled (i.e, single-file) assemblies, but we can't be confident
322+
// that whenever Assembly.Location is empty the corresponding assembly is bundled.
323+
//
324+
// Provisionally assume that the entry-assembly is bundled. If this query is for something other
325+
// than the entry-assembly, then return nothing.
326+
if (assembly == Assembly.GetEntryAssembly())
327+
{
328+
return Path.Combine(
329+
AppContext.BaseDirectory,
330+
assembly.GetName().Name + ".xml");
331+
}
332+
333+
return string.Empty;
317334
}
318335
}
319336
}

0 commit comments

Comments
 (0)