Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Using Roslyn Source Generators with attribute class fails #9619

Closed
paulushub opened this issue Jan 17, 2024 · 2 comments
Closed

[Bug] Using Roslyn Source Generators with attribute class fails #9619

paulushub opened this issue Jan 17, 2024 · 2 comments
Labels
bug A bug to fix

Comments

@paulushub
Copy link

paulushub commented Jan 17, 2024

Describe the bug
Trying to document a source code which has attribute classes generated by the source generators.

  • Without generating attribute classes, docfx works without any error.
  • With attribute class, the build fails with error below

MyClass.cs(11,6): error CS0246: The type or namespace name 'ElementFactoryAttribute' could not be
found (are you missing a using directive or an assembly reference?)

To Reproduce
Steps to reproduce the behavior:

  1. Create any sample Generator project and have it generate an attribute class; say ElementFactoryAttribbute
  2. Create a project to use the generated classes and use the attribute on a class.
  3. Create a docfx project and serve.

Expected behavior
The build to work with a generated attribute class.

Context:

  • OS: Windows Desktop
  • Docfx version: 2.75.1

Additional context

namespace HelloWorldGenerated
{
    /// <summary>
    /// Enter description here for class X.
    /// ID string generated is "T:MyNamespace.MyClass".
    /// </summary>
    [ElementFactory]
    public class MyClass
    {
        /// <summary>
        /// Enter description here for the first constructor.
        /// ID string generated is "M:MyNamespace.MyClass.#ctor".
        /// </summary>
        public MyClass() { }

        /// <summary>
        /// Enter description here for the second constructor.
        /// ID string generated is "M:MyNamespace.MyClass.#ctor(System.Int32)".
        /// </summary>
        /// <param name="i">Describe parameter.</param>
        public MyClass(int i) { }

        /// <summary>
        /// Enter description here for field Message.
        /// ID string generated is "F:MyNamespace.MyClass.Message".
        /// </summary>
        public string Message;
     }
}
@paulushub paulushub added the bug A bug to fix label Jan 17, 2024
@paulushub paulushub changed the title [Bug] Roslyn Source Generators with attribute class fails [Bug] Using Roslyn Source Generators with attribute class fails Jan 17, 2024
@filzrev
Copy link
Contributor

filzrev commented Jan 18, 2024

On my environment.
It can be resolved by executing command with following orders.

  1. dotnet build -c Release
  2. docfx metadata

Background
docfx metadata command build projects by using MSBuildWorkspace with Release configuration.
But it doesn't generate physical DLL files.

So project's analyzer is resolved to UnresolvedAnalyzerReference.
And it's silently skipped without source generation.

@paulushub
Copy link
Author

@filzrev Thanks for the help.
The following did resolve the issue as you said (without dotnet build -c Release, the docfx metadata failed):

  1. dotnet build -c Release
  2. docfx metadata
  3. docfx docfx.json

If there is no plan to directly support this use case, then I will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug to fix
Projects
None yet
Development

No branches or pull requests

3 participants