DEV Community

Chris Richmond
Chris Richmond

Posted on

Creating Multi-platform nugets for Xamarin

Problem:
You want to create nuget packages that have different dependencies for multiple platforms such as Xamarin iOS and Android and beyond.

Solution:
Create a nuspec file that includes dependencies and files that match the platforms you want to target as such.

<?xml version="1.0"?>
<package >
  <metadata>
    ... 
 <dependencies>

      <group targetFramework="Xamarin.iOS10"> 
        <dependency id="Microsoft.AspNetCore.SignalR.Client" version="5.0.9" />
        <dependency id="Microsoft.Extensions.Http" version="5.0.0" />
        <dependency id="System.Reactive" version="5.0.0" /> 
      </group>

      <group targetFramework="MonoAndroid10"> 
        <dependency id="Microsoft.AspNetCore.SignalR.Client" version="5.0.9" />
        <dependency id="Microsoft.Extensions.Http" version="5.0.0" />
        <dependency id="System.Reactive" version="5.0.0" /> 
      </group>

      <group targetFramework="net7.0"> 
        <dependency id="Microsoft.AspNetCore.SignalR.Client" version="5.0.9" />
        <dependency id="Microsoft.Extensions.Http" version="5.0.0" />
        <dependency id="System.Reactive" version="5.0.0" /> 
      </group>
    <group targetFramework="netstandard2.1"> 
        <dependency id="Microsoft.AspNetCore.SignalR.Client" version="5.0.9" />
        <dependency id="Microsoft.Extensions.Http" version="5.0.0" />
        <dependency id="System.Reactive" version="5.0.0" /> 
      </group>
    </dependencies>

  </metadata>
    <files>    
      <file src="[dllpath]" target="lib\netstandard2.1" />
      <file src="[dllpath]" target="lib\net7.0" />
      <file src="[dllpath]" target="lib\MonoAndroid10" />
      <file src="[dllpath]" target="lib\Xamarin.iOS10" />
    </files>
</package>
Enter fullscreen mode Exit fullscreen mode

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay