You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过MSBuild在Xamarin.Forms PCL项目指定构建包含的语言

Control Included Localization Languages in Xamarin.Forms Builds (No .csproj Edits)

Got it, let's tackle this problem step by step. You want to control which languages are included in your Xamarin.Forms build without touching any .csproj files—totally doable with MSBuild global properties, since they let you override project settings at build time. Here's how to handle each project type in your solution:


1. PCL/NetStandard Shared Project

For your shared .resx files, MSBuild has a built-in SatelliteResourceLanguages property that controls which satellite assemblies get generated. Pass this property via the command line to limit output to your target languages.

Command Line Parameter:

/p:SatelliteResourceLanguages=en,fr,de

This tells the resource generator to only create satellite assemblies for English, French, and German. Any .resx files for other languages will be ignored during the build.


2. Android Project

Android uses values-xx resource folders for localization. To filter these, use the Android-specific AndroidResgenLanguages property. This ensures only your target language folders are processed and included in the APK.

Command Line Parameter:

/p:AndroidResgenLanguages=en,fr,de

If your Android project also includes .resx files (e.g., for platform-specific strings), combine this with the SatelliteResourceLanguages parameter from the shared project to cover both cases.


3. UWP Project

UWP stores localization in Strings/xx-xx folders (e.g., Strings/en-us). Use the SupportedLanguages property to define which languages are included in the final app package. For .resx files in UWP, you can also use SatelliteResourceLanguages to control satellite assemblies.

Command Line Parameters:

/p:SupportedLanguages=en-us,fr-fr,de-de /p:SatelliteResourceLanguages=en,fr,de

Note that UWP uses full culture codes (like en-us instead of en) for its string folders, so adjust the SupportedLanguages values to match your folder structure.


Full MSBuild Command Example

Putting it all together, here's a complete command to build your entire solution with only English, French, and German localization:

msbuild YourSolution.sln /p:Configuration=Release /p:SatelliteResourceLanguages=en,fr,de /p:AndroidResgenLanguages=en,fr,de /p:SupportedLanguages=en-us,fr-fr,de-de

Key Notes

  • Language Code Consistency: Make sure the language codes match your project's folder/resx naming. For example, if your Android values folder is values-en-rUS, use en-US for AndroidResgenLanguages.
  • CI/CD Friendly: These parameters work perfectly in CI/CD pipelines (Azure DevOps, GitHub Actions, etc.)—just add them as build variables or script arguments.
  • Validation: After building, check the output directories:
    • Shared project: Look for language-specific subfolders (e.g., en/, fr/) in the output bin folder.
    • Android: Verify only target values-xx folders exist in the APK's resources.
    • UWP: Check the Appx/Strings folder in the output—only your specified languages should be present.

内容的提问来源于stack exchange,提问作者Alexey Vukolov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:56:16