Publish with "Trim unused code" #141
-
I'm trying to publish a simple console app with CliFx and a single When trimmed it's about 12-13MB, but not working. It returns the error, only when specifically using
When only using the following, it doesn't see the DefaultCommand at all, probably because it discards it before adding it: .SetExecutableName("app")
.AddCommandsFromThisAssembly() Already tried the following: [Command]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public class DefaultCommand : ICommand
{
public DefaultCommand()
{
}
[CommandOption("input-path", 'p', Description = "Input Path")]
public string InputPath { get; set; } = string.Empty;
...
} Source: Anyone has more info about this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
CliFx is not trim-compatible in its current state and it would take a lot of effort to make it compatible (essentially rewriting it with source-generators), due to the heavy use of type-walking and dynamic type conversions. In order to get your CLI app working with CliFx with assembly trimming, you have to manually preserve your commands, converters, and other dynamically referenced members (such as See here for a working example: https://github.com/Tyrrrz/DiscordChatExporter/blob/c8ea365c04498bea973c38e2ed028e8c31a05bb0/DiscordChatExporter.Cli/Program.cs#L13-L40. Feel free to narrow the |
Beta Was this translation helpful? Give feedback.
CliFx is not trim-compatible in its current state and it would take a lot of effort to make it compatible (essentially rewriting it with source-generators), due to the heavy use of type-walking and dynamic type conversions.
In order to get your CLI app working with CliFx with assembly trimming, you have to manually preserve your commands, converters, and other dynamically referenced members (such as
Parse(...)
methods on applicable types, when used for conversion).See here for a working example: https://github.com/Tyrrrz/DiscordChatExporter/blob/c8ea365c04498bea973c38e2ed028e8c31a05bb0/DiscordChatExporter.Cli/Program.cs#L13-L40. Feel free to narrow the
DynamicallyAccessedMemberTypes
to t…