Visual Studio 2019 年无法将 LocBaml 与 WPF .Net 5.0 项目一起使用

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

我有一个非常简单的 WPF 项目 (.Net 5.0),我正在尝试对其进行本地化。

我下载了 locbaml 工具项目作为 wpf 示例的一部分,并在 Visual Studio 2019 - 发布模式中构建了它。这样就OK了。

我已经 运行“MSBuild”将 UID (msbuild /t:updateid WPFLocalizationWithXAML.csproj) 添加到我的项目中。这工作正常并添加了 UID。

我的问题是我无法用“LocBaml.exe”解析“WPFLocalizationWithXAML.resources.dll”。我已将“LocBaml.exe”(如上所示)和“WPFLocalizationWithXAML.exe”复制到“\en-us”文件夹中,以便它们与“WPFLocalizationWithXAML.resources.dll”放在一起。然后我 运行 下面的命令 (locbaml /parse WPFLocalizationWithXAML.resources.dll /out:trans.csv) 但这总是导致以下错误和一个 trans.cvs 文件里面有垃圾:

"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"

此致

如您所见,LocBAML 工具仍然使用 .NET Framework 4.7.2 in its project file。它尚未移植到 .NET Core 和 .NET 5,并且不兼容。 GitHub.

上有一个未解决的问题

请记住,LocBAML 工具从未打算用于生产,请参阅 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.

作为替代方案,您可以使用资源文件 (.resx) 进行本地化,例如: