Search code examples
c#wpflocalization.net-5locbaml

Can't use LocBaml with WPF .Net 5.0 project in Visual Studio 2019


I have a very simple WPF project (.Net 5.0) that I'm trying to localize.

I downloaded the locbaml tool project as part of the wpf samples and I built it in Visual Studio 2019 - Release mode. This built OK.

I've run "MSBuild" to add the UID's (msbuild /t:updateid WPFLocalizationWithXAML.csproj) to my project. This worked ok and added the UID's.

My problem is that I can't parse "WPFLocalizationWithXAML.resources.dll" with "LocBaml.exe". I've copied "LocBaml.exe" (as built above) and "WPFLocalizationWithXAML.exe" into the "\en-us" folder so that they sit with "WPFLocalizationWithXAML.resources.dll". I then ran the following command (locbaml /parse WPFLocalizationWithXAML.resources.dll /out:trans.csv) but this always results in the following error and a trans.cvs file wth garbage in it:

"Microsoft (R) Baml Localization Utility 1.0.0.0 Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified"

Regards


Solution

  • The LocBAML tool still uses .NET Framework 4.7.2 as you can see in its project file. It is not yet ported to .NET Core and .NET 5 and incompatible to them. There is an open issue on GitHub.

    Remember that the LocBAML tool was never intended to be used in production, see documentation.

    The LocBaml tool is not a production-ready application. It is presented as a sample that uses some of the localization APIs and illustrates how you might write a localization tool.

    As an alternative, you could do localization using resource files (.resx), see for example: