Skip to content

[Feature Request] Add support to reference additional DLLs when build metadata with C# source files #9706

@filzrev

Description

@filzrev

Is your feature request related to a problem? Please describe.

It seems C# file based API metadata generation are used by users who use Unity.

In this case. It needs to reference additional DLLs that are provided by Unity. (e.g. UnityEngine.dll)
But It seems currently not possible by docfx.json config.

It can generate API metadata partially. When setting "allowCompilationErrors": true.
But some metadata that depends on external DLLs are not generated.

Describe the solution you'd like
Allow additional DLL file references when using C# file based build.

Additional context
Currently CreateCompilationFromCSharpFiles don't support additional references.
But CreateCompilationFromCSharpCode that used test code supports additional DLL references.

public static Compilation CreateCompilationFromCSharpFiles(IEnumerable<string> files)
{
return CS.CSharpCompilation.Create(
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 = null, params MetadataReference[] references)
{
return CS.CSharpCompilation.Create(
name,
options: new CS.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, xmlReferenceResolver: XmlFileResolver.Default),
syntaxTrees: new[] { CS.SyntaxFactory.ParseSyntaxTree(code) },
references: GetDefaultMetadataReferences("C#").Concat(references));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnetGenerate .NET API reference docs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions