WinUI 3 localized strings resources don't work when app is built using dotnet build command

50 views Asked by At

I have WinUI 3 application written in C#. I have multiple project in solution.

  • App.Views - Views (XAML Window and Pages)
  • App.ViewModels - View models
  • App.Strings - RESW files and string resources manager class
  • App - Main project

App references all other projects, App.Strings is referenced by all other projects and App.ViewModels is referenced by App.Views.

I use string resources in App.Views using x:Uid:

<TextBlock x:Uid="/App.Strings/HomeViewResources/FileTextBlock">

As I written before I also have static class for access resources in C# code:

using Windows.ApplicationModel.Resources;
using System;

public static class StringResourcesManager
{
    #region PROPERTIES

    public static StringResource HomeView { get; } = BuildResource("HomeViewResources");

    #endregion



    #region PRIVATE METHODS

    private static StringResource BuildResource(string resourceName)
    {
        ResourceLoader loader = new ResourceLoader($"App.Strings/{resourceName}");
        return new StringResource(loader);
    }

    #endregion
}

public class StringResource
{
    #region FIELDS

    protected ResourceLoader _resourceLoader;

    #endregion



    #region CONSTRUCTORS

    internal StringResource(ResourceLoader resourceLoader)
    {
        _resourceLoader = resourceLoader;
    }

    #endregion



    #region PUBLIC METHODS

    public string Get(string key)
    {
        return _resourceLoader.GetString(key);
    }

    #endregion
}

When I'm running application with Visual Studio application runs normally, but when I build application with dotnet publish and run exe file, application throws "ResourceMap Not Found" exception at this line: ResourceLoader loader = new ResourceLoader($"App.Strings/{resourceName}");.

Edit 1:

I tried to use dotnet build instead of dotnet publish and application seems to work normally, when built locally. But I want to use this command in Github Actions and when I try to run .exe file built with dotnet build in workflow, the same problem occurs.

0

There are 0 answers