Cysharp / ConsoleAppFramework

Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
MIT License
1.66k stars 95 forks source link

I can't get it to work with a command class. #136

Closed mikeholczer closed 4 months ago

mikeholczer commented 4 months ago

Things are working as expected when I specify commands with lambdas, but when I try to use the .Add() method to specify commands in a class, nothing happens when I run the application. I can't even get --help or --version to work. When debugging, it seems as though the ConsoleApp.Builder.g.cs file isn't getting compiled in, as the debugger just skips over the line calling it in ConsoleApp.cs's ConsoleAppFramework.ConsoleApp.ConsoleAppBuilder.RunAsync(string[] args). Like it's no seeing the other side of the partial method.

When I comment out the .Add() call, it works again. Any ideas what I'm doing wrong?

neuecc commented 4 months ago

Could you provide full reproducible code?

mikeholczer commented 4 months ago

Well, I’m not able to recreate the issue in a simple sample app I created for the purpose. I’ll have to start making it more and more like my real app, and see when the issue reproduces. I should have done that to start off. I think I’ll have time tomorrow for that.

mikeholczer commented 4 months ago

So, I think I figured out what my problem is which is it doesn't work if I use a command class that's declared in another project. If I add a project to my solution, add a project refence in the console app to it. I just created this follow class in the other project and if I use that as the generic type on the call to .Add(). than none of the ConsoleAppFramework functionality works, not just that commands, other commands defined as lamdas stop working too. Is that just not a supported use case?

using System;

namespace ClassLibrary1
{
    public class Class1
    {
        public void TestMethod()
        {
            Console.WriteLine("testing");
        }
    }
}
mikeholczer commented 4 months ago

As soon as I move that class to the console app project, it all works.

neuecc commented 4 months ago

Thank you. Due to limitations of the Source Generator, it is not possible to obtain the SyntaxTree of the referenced project. It seems that it is impossible to process it all because the ConsoleAppFramework also obtains information from the SyntaxTree (DocComment).

I've made the Analyzer output errors for now(v5.2.3).