如何通过MSBuild在Xamarin.Forms PCL项目指定构建包含的语言
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
valuesfolder isvalues-en-rUS, useen-USforAndroidResgenLanguages. - 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-xxfolders exist in the APK's resources. - UWP: Check the
Appx/Stringsfolder in the output—only your specified languages should be present.
- Shared project: Look for language-specific subfolders (e.g.,
内容的提问来源于stack exchange,提问作者Alexey Vukolov

