From 2fbe4ef4df3dfac1bf101b8d9d2cdfd59531cf41 Mon Sep 17 00:00:00 2001 From: Yufei Huang Date: Wed, 12 Apr 2023 21:26:01 +0800 Subject: [PATCH] fix: hide generated assembly name --- .../CompilationHelper.cs | 20 +++++++++---------- .../Visitors/SymbolVisitorAdapter.cs | 2 +- .../modern/partials/class.header.tmpl.partial | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.DocAsCode.Dotnet/CompilationHelper.cs b/src/Microsoft.DocAsCode.Dotnet/CompilationHelper.cs index 8e6bd28fd70..c4dac00bb63 100644 --- a/src/Microsoft.DocAsCode.Dotnet/CompilationHelper.cs +++ b/src/Microsoft.DocAsCode.Dotnet/CompilationHelper.cs @@ -18,11 +18,11 @@ internal static class CompilationHelper { CS.SyntaxFactory.ParseSyntaxTree( """ - class Bootstrap - { - public static void Main(string[] foo) { } - } - """), + class Bootstrap + { + public static void Main(string[] foo) { } + } + """), }; public static bool CheckDiagnostics(this Compilation compilation, bool errorAsWarning) @@ -56,13 +56,13 @@ public static bool CheckDiagnostics(this Compilation compilation, bool errorAsWa public static Compilation CreateCompilationFromCSharpFiles(IEnumerable files) { return CS.CSharpCompilation.Create( - assemblyName: "cs.temp.dll", + assemblyName: null, options: new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, xmlReferenceResolver: XmlFileResolver.Default), syntaxTrees: files.Select(path => CS.SyntaxFactory.ParseSyntaxTree(File.ReadAllText(path), path: path)), references: GetDefaultMetadataReferences("C#")); } - public static Compilation CreateCompilationFromCSharpCode(string code, string name = "cs.temp.dll", params MetadataReference[] references) + public static Compilation CreateCompilationFromCSharpCode(string code, string name = null, params MetadataReference[] references) { return CS.CSharpCompilation.Create( name, @@ -74,13 +74,13 @@ public static Compilation CreateCompilationFromCSharpCode(string code, string na public static Compilation CreateCompilationFromVBFiles(IEnumerable files) { return VB.VisualBasicCompilation.Create( - assemblyName: "vb.temp.dll", + assemblyName: null, options: new VB.VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, globalImports: GetVBGlobalImports(), xmlReferenceResolver: XmlFileResolver.Default), syntaxTrees: files.Select(path => VB.SyntaxFactory.ParseSyntaxTree(File.ReadAllText(path), path: path)), references: GetDefaultMetadataReferences("VB")); } - public static Compilation CreateCompilationFromVBCode(string code, string name = "vb.temp.dll", params MetadataReference[] references) + public static Compilation CreateCompilationFromVBCode(string code, string name = null, params MetadataReference[] references) { return VB.VisualBasicCompilation.Create( name, @@ -93,7 +93,7 @@ public static (Compilation, IAssemblySymbol) CreateCompilationFromAssembly(strin { var metadataReference = CreateMetadataReference(assemblyPath); var compilation = CS.CSharpCompilation.Create( - "EmptyProjectWithAssembly", + assemblyName: null, options: new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), syntaxTrees: s_assemblyBootstrap, references: GetReferenceAssemblies(assemblyPath) diff --git a/src/Microsoft.DocAsCode.Dotnet/Visitors/SymbolVisitorAdapter.cs b/src/Microsoft.DocAsCode.Dotnet/Visitors/SymbolVisitorAdapter.cs index e335dd44356..59e65ce7176 100644 --- a/src/Microsoft.DocAsCode.Dotnet/Visitors/SymbolVisitorAdapter.cs +++ b/src/Microsoft.DocAsCode.Dotnet/Visitors/SymbolVisitorAdapter.cs @@ -52,7 +52,7 @@ public override MetadataItem DefaultVisit(ISymbol symbol) item.DisplayQualifiedNames = new SortedList(); item.Source = VisitorHelper.GetSourceDetail(symbol, _compilation); var assemblyName = symbol.ContainingAssembly?.Name; - item.AssemblyNameList = string.IsNullOrEmpty(assemblyName) ? null : new List { assemblyName }; + item.AssemblyNameList = string.IsNullOrEmpty(assemblyName) || assemblyName is "?" ? null : new List { assemblyName }; if (symbol is not INamespaceSymbol) { var namespaceName = VisitorHelper.GetId(symbol.ContainingNamespace); diff --git a/templates/modern/partials/class.header.tmpl.partial b/templates/modern/partials/class.header.tmpl.partial index cf015518c82..2ff541eae91 100644 --- a/templates/modern/partials/class.header.tmpl.partial +++ b/templates/modern/partials/class.header.tmpl.partial @@ -7,7 +7,7 @@
{{__global.namespace}}
{{{namespace.specName.0.value}}}
-
{{__global.assembly}}
{{assemblies.0}}.dll
+ {{#assemblies.0}}
{{__global.assembly}}
{{assemblies.0}}.dll
{{/assemblies.0}}
{{{summary}}}