Localized strings in a shared Visual Studio project

I am trying to use the collaborative project concept to split client application logic between WPF and Android (Xamarin.Forms) project. In both projects, I want to use the same localizable texts, so it makes sense for me to move the resource file (with the texts) into a common project.

The following example is from a WPF project, but the problem is with shared projects, not WPF.

In my WPF project in XAML based views, I access string values ​​like this:

<TextBlock Text="{x:Static i18n:Strings.WelcomeMessage}" />

      

The file Strings.resx

and its translation are in the folder I18N

, i.e. they don't fit in the project root. Therefore, the generated one public class Strings

is placed in the namespace TestApp.I18N

. When the I18N folder belongs to a direct WPF project everything works fine, but if I move I18N to a shared project the WPF application crashes with the exception:

Could not find resources suitable for the specified culture or neutral culture. Make sure "TestApp.I18N.Strings.resources" was properly embedded or linked to the WPF assembly at compile time, or that all required assemblies are loadable and fully signed.

If I view the compiled assembly with some disassembly tool, I can see the difference between both compilations:

  • In compilation, where the I18N folder belongs to the shared project, I see a resource named TestApp.Strings.resources

  • In the compilation where the I18N folder belongs to the WPF project, I see a resource named TestApp.I18N.Strings.resources

This actually explains why the application crashes in the first case. And it is clear which workaround method can be used (I can put Strings.resx

and link it to the project root). But I feel that having resources in a collaborative project is not a good idea because there is a lack of proper support. Can anyone share their own experience in this direction? Why are resource files from a shared project interpreted differently by the compiler?

+3


source to share





All Articles