-
Notifications
You must be signed in to change notification settings - Fork 6
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
PublishTrimmed/TrimMode support? #44
Comments
Hi! I'm away from my laptop for a few days. I've never tried it with trimming. I'll take a look when I'm back. ;) |
Can you create and share a reproducible project on GitHub? |
Hey sorry I've not got around to this yet, I will try and get something for you this week |
Here is an attached reproducible project, sorry for the delay! You should be able to run this sln, F5 to run locally which will load the nav bar content and the title bar. Then in Developer Powershell in VisualStudio, run
and run the exe from that directory. Result is none of the strings get loaded. You can see some trim warnings coming out of the publish step also. Turning off partial trim causes the app to crash instead of just not loading. Let me know if I can provide anything else to assist |
@AndrewKeepCoding, is there anything else I can provide to help you out with this? Is the test project OK? |
Hi @Lawls91! I tried to reproduce the issue but as you can see, the strings are loaded as expected. Can you make sure that the Strings folder and its Resources.resw files exist aside the EXE? |
Hey @AndrewKeepCoding , no problem! I cant claim to understand the trim process fully, but I think that the assemblies in the /bin/Release folder are created before the trim? Please after running the above dotnet publish step run the exe from the trimmed output directory. Should be: SOLUTION_DIRECTORY/x64/LocalizerTestApp/LocalizerTestApp.exe From there, when you run it, the strings dont display. The Strings directory is alongside it also Let me know if you are able to see this behaviour also |
It works. Can you add a logger from the builder? <Page
x:Class="LocalizerTestApp.Pages.HomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="88"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Home" FontSize="28" />
<StackPanel Grid.Row="1">
<TextBlock x:Name="StringsFolderPath"/>
<TextBlock x:Name="CurrentLanguage"/>
<ListView x:Name="AvailableLanguages"/>
<ListView x:Name="LanguageDictionaries"/>
</StackPanel>
</Grid>
</Page> public HomePage()
{
InitializeComponent();
Loaded += HomePage_Loaded;
}
private void HomePage_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
StringsFolderPath.Text = Path.Combine(AppContext.BaseDirectory, "Strings");
CurrentLanguage.Text = Localizer.Get().GetCurrentLanguage();
AvailableLanguages.ItemsSource = Localizer.Get().GetAvailableLanguages();
LanguageDictionaries.ItemsSource = Localizer.Get().GetLanguageDictionaries().FirstOrDefault().GetItems().Select(item => item.Value);
} |
@AndrewKeepCoding accessing by code works (the "APP TITLE BAR" works for example and thats setup in the constructor of MainWindow.xaml.cs). It appears to just be strings that are setup through the XAML directly that dont work. I added that extra stuff for you, you can see it is outputting, but the strings for the nav bar still arent (when using the trimmed published exe, as mentioned the exe inside the project folder works, its the one off the solutions directory that doesnt) I've attached a prebuilt copy, if you are launching it from SOLUTION_DIRECTORY/x64/LocalizerTestApp/LocalizerTestApp.exe already, then maybe its related to the compiler? Please can you run this and check behaviour? (Sorry, had to double compress it with 7z for github) |
Hey @AndrewKeepCoding just wondering if you missed my latest reply? |
In a couple of days, I'll have access to a pc for testing. The thing is that I just can't run files on the laptop I use for work. 😅 |
Makes sense, no problem, thanks for the reply! Let me know if theres anything I can provide to help. I've tested on a couple other machines with some of our other devs and get the same behaviour, whereby the output in SOLUTION_DIRECTORY/x64 doesnt work, but it does in SOLUTION_DIRECTORY/PROJECT_DIRECTORY/bin/Release (assume thats not Trimmed yet in there) |
@Lawls91 I finally managed to reproduce the issue. Even though the localizer has the resources loaded as expected, it’s failing to get the properties from the controls. It seems that this is because ‘Reflection’ doesn’t work well with trimming. See here. I'm not sure if we'll have a better way to handle this in the future or not. I'm sorry I couldn't bring better news after all. |
@AndrewKeepCoding Is it worth investigating opting the localizer modules out of trimming? Reading this, it seems like partial trimming should work with that package just set to not trim (I've not really dug into that though) |
I tried it but still didn't work...😵 |
@Lawls91 Can you try trimming with the WinUI3Localizer sample app? It seems to be working. |
Hi @Lawls91 ! |
Hey,
I am trying to use the library, which works fine untrimmed. Unfortunately we are having issues with TrimmedMode with .NET7/8, in which the app crashes at launch.
I have managed to resolve this by using TrimMode partial as suggested here microsoft/WindowsAppSDK#2478 (comment) which has the app running but none of the strings are being loaded in. Its tricky to debug as its occuring after a publish.
Does WinUI3Localizer support trimmed apps / partially trimmed apps with .NET 7/8?
The text was updated successfully, but these errors were encountered: