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

Top comments (0)