How to Build a NuGet Package for .NET MAUI Android and iOS Development

Prerequisites

Download Dynamsoft Mobile Barcode Scanner SDK

Creating .NET Binding Libraries for Android and iOS

Assume you have installed Visual Studio 2022 Preview on Windows and macOS. Although installing Visual Studio for Mac is not necessary that you can pair to macOS remotely, the output packages of .NET binding libraries for iOS are different between Windows and macOS. We will talk about it in the following paragraphs.

Visual Studio Library Binding Project

When searching for binding in Visual Studio 2022, you will see there are two kinds of library binding projects. One for Xamarin, and the other for .NET 6. To build .NET MAUI-compatible librayr, we select the project templates without (Xamarin).

Binding Android AAR Package for .NET 6

  1. Drag DynamsoftBarcodeReader.aar to the Android binding project.
  2. Select DynamsoftBarcodeReader.aar and change build action to AndroidLibrary.
  • android.dll
  • android.pdb
  • android.xml
  • DynamsoftBarcodeReader.aar

Binding iOS Framework for .NET 6

  1. Drag DynamsoftBarcodeReader.xcframework to the iOS binding project.
  2. Add following code to the csproj file.
<ItemGroup>
<NativeReference Include="DynamsoftBarcodeReader.xcframework">
<Kind>Framework</Kind>
<Frameworks></Frameworks>
</NativeReference>
</ItemGroup>
  • ios.dll
  • ios.pdb
  • ios.resources
  • DynamsoftBarcodeReader.xcframework

Packing Android and iOS SDKs into a Single NuGet Package on Windows

Since we have built Android and iOS packages using Visual Studio, we can publish them respectively to NuGet.org. But, what if you want to build them into a single NuGet package? We can use nuspec file to implement this.

  1. Create a nuspec file.
nuget spec
<files>
<file src="README.md" target="" />

<file src="android/bin/Release/net6.0-android/android.dll" target="lib/net6.0-android31.0/" />
<file src="android/bin/Release/net6.0-android/android.xml" target="lib/net6.0-android31.0/" />
<file src="android/bin/Release/net6.0-android/DynamsoftBarcodeReader.aar" target="lib/net6.0-android31.0/" />

<file src="ios/bin/Release/net6.0-ios/ios.dll" target="lib/net6.0-ios15.4/" />
<file src="ios/manifest" target="lib/net6.0-ios15.4/ios.resources" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/Info.plist" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework" />

<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework/Info.plist" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework/DynamsoftBarcodeReader" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework/Headers/DynamsoftBarcodeReader.h" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework/Headers" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework/Headers/DynamsoftBarcodeSDK.h" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework/Headers" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework/Modules/module.modulemap" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64/DynamsoftBarcodeReader.framework/Modules" />

<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework/Info.plist" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework/DynamsoftBarcodeReader" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework/Headers/DynamsoftBarcodeReader.h" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework/Headers" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework/Headers/DynamsoftBarcodeSDK.h" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework/Headers" />
<file src="ios/bin/Release/net6.0-ios/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework/Modules/module.modulemap" target="lib/net6.0-ios15.4/ios.resources/DynamsoftBarcodeReader.xcframework/ios-arm64_x86_64-simulator/DynamsoftBarcodeReader.framework/Modules" />
</files>

Try .NET MAUI Barcode QR Code Scanner

https://github.com/yushulx/maui-barcode-qrcode-scanner

Source Code

https://github.com/yushulx/barcode-dotnet-mobile

--

--

Manager of Dynamsoft Open Source Projects | Tech Lover

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store