-
-
Notifications
You must be signed in to change notification settings - Fork 519
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
Multiple errors when trying to ILLink/Trim a console app that uses Spectre. #955
Comments
@azchohfi Not sure what the solution for this is tbh. Any pointers? |
Oh, absolutely! |
Btw, something like this can be used as a good test: |
@azchohfi Thanks for the suggestion. This is something we should consider for the 1.0.0 release of Spectre.Console.Cli. We've recently (in 0.45.0) moved the CLI parts out to its own NuGet package (Spectre.Console.Cli), so if you only need the console parts (Spectre.Console), you should be able to trim that now. |
Oh, interesting. I'll try that! |
This version is MUCH better, but still have the same issues as before on that assembly.
|
The size difference between trimmed and untrimmed console application, for me at least is night and day (66k before trimming, 12k after trimming). It would be lovely if Spectre can work with assembly trimming. For example if I have a command like this: internal sealed partial class DownloadCommand : AsyncCommand<Settings>
{
public sealed class Settings : CommandSettings and configure it like so: var app = new CommandApp<DownloadCommand>(); Then the application produces a trim warning, and when executed regardless breaks down like so:
I assume the problem is hidden somewhere much more deeper though. |
While waiting for native support for Spectre trimming, it is possible to use |
In order to use Microsofts Otherwise it is an error when trimming is enabled. |
You need to add the following attribute to your class Program {
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicNestedTypes, typeof(YourCommand))]
public static void Main(string[] args) {
...
}
} That way the trimming won't throw away your command types or their nested settings classes. |
I suggest per #955 (comment) I would be best to add the attribute to the |
Information
Describe the bug
When trying to use Spectre on a console app that targets .NET6, and trying to build a self-contained library, I get multiple ILLink errors, such as IL2070, IL2072, IL2067, IL2072, IL2026, and IL2087.
To Reproduce
Reference Spectre.Console 0.44.0 from a console app, use something from Spetre, and build with PublishTrimmed=True, PublishSingleFile=True, "--self-contained -r win-x64 -f net6.0". Multiple errors.
Expected behavior
Builds and works fine.
Additional context
Please upvote 👍 this issue if you are interested in it.
The text was updated successfully, but these errors were encountered: