Xamarin原生与Xamarin Forms的NuGet包输出及跨平台开发选型咨询
Hey there! Let's walk through your options and clear up that NuGet confusion—you’ve got a solid starting point with your existing Xamarin Native Android app, so let’s align the choices with your core needs.
技术选型:Xamarin Native iOS vs Xamarin Forms
First, let’s break down the pros and cons of each approach for your scenario:
Xamarin Native iOS
- Pros: Since you already know Xamarin Android Native, you’ll pick up Xamarin iOS Native quickly—both use platform-specific APIs, so you’ll have full control over iOS’s native UI, performance, and platform-specific behaviors. This is ideal if you need pixel-perfect native experiences or have complex platform-specific requirements.
- Cons: You’ll have to maintain two separate codebases (Android and iOS), which means duplicate work for feature updates and bug fixes. For NuGet packages, you’ll need to build two separate packages (one for Android, one for iOS) since the implementations are platform-specific.
Xamarin Forms
- Pros: The biggest win here is code sharing—you can reuse most of your business logic, view models, and even UI components across both platforms. For your existing Android app, you can gradually migrate shared logic to a Forms-compatible class library, then build the iOS UI using Forms (or mix in native controls where needed). This cuts down on repetitive work long-term.
- Cons: If you need highly customized native UI, you’ll have to write custom renderers or use dependency services, which adds a small learning curve. For most standard apps, though, this isn’t a major issue, and performance is more than sufficient for everyday use.
Your Core Question: NuGet Packages with Xamarin Forms
Great news—you don’t need two separate NuGet packages! Xamarin Forms supports multi-targeting, which lets you build a single NuGet package that includes platform-specific code alongside shared logic. Here’s how it works:
- Create a multi-targeted class library that targets
netstandard2.0(for shared code like view models, data handling, or cross-platform utilities),Xamarin.iOS, andXamarin.Android. - Put your shared business logic in the netstandard project, and any platform-specific implementations (like native API calls, custom control logic) in the respective platform targets.
- When you pack this project into a NuGet, it will automatically include all platform-specific assets. When you reference the package in your Forms app, it pulls the correct code for the current platform (Android or iOS) without any extra work on your end.
Quick Additional Tips
- If you might expand to other platforms (like UWP) down the line, Xamarin Forms is the better bet—your shared code will translate seamlessly.
- If your existing Android app has a lot of highly customized native UI, consider a hybrid approach first: extract your shared business logic into a multi-targeted NuGet, build the iOS app with Native initially, then gradually migrate UI components to Forms as you have time.
- Forms has built-in UI testing tools that work across platforms, so you’ll spend less time writing duplicate test cases for Android and iOS.
内容的提问来源于stack exchange,提问作者Srusti Thakkar
相关产品推荐
相关产品推荐

