如何在VS2017 for Mac的Xamarin iOS中按Target选择对应xcassets
How to Use Target-Specific XCAssets in Visual Studio 2017 for Mac (Xamarin.iOS)
Got it, let’s walk through how to set this up—this is totally doable, just a bit different from Xcode’s workflow. Here’s how to replicate that target-specific asset behavior for your Xamarin.iOS project:
Step 1: Create Separate XCAssets Catalogs
- Right-click your Xamarin.iOS project > Add > New File
- Pick iOS > Asset Catalog from the template list, name it something like
CustomerAImages.xcassets(repeat this for every customer/target you need) - Add your unique images to each catalog—feel free to use identical image names across catalogs since they’ll be tied to different targets
Step 2: Assign Target Membership to Each XCAssets
This is the critical step that mirrors Xcode’s target selection:
- In the Solution Explorer, select one of your
xcassetscatalogs - Open the Properties Pad (if it’s hidden, go to View > Pad > Properties)
- First, confirm the Build Action dropdown is set to
BundleResource—this ensures the assets get bundled with the app - Expand the Target Membership section (it might be collapsed by default)
- Uncheck all target boxes except the one this catalog belongs to. For example,
CustomerAImages.xcassetsshould only have theCustomerATargetbox checked, and same logic applies to other catalogs.
Step 3: Use Images as Normal
- Reference images in your code just like you usually would (e.g.,
UIImage.FromBundle("Logo")) - When you build a specific target, only the
xcassetscatalog marked for that target will be included in the app bundle—so the correct image loads automatically.
Quick Troubleshooting Tips
- If images don’t show up, double-check the Target Membership settings—this is the most common misstep
- Ensure every
xcassetshas a build action ofBundleResource(notNoneor any other option) - Clean and rebuild your solution after adjusting target membership to make sure old assets are cleared from the bundle
内容的提问来源于stack exchange,提问作者Seeking guidance
相关产品推荐
相关产品推荐

