title: How to multitarget in Xamarin.Forms with Visual Studio for Mac?
body: <p>I started out creating a <code>.NET Standard Library</code> that I intended to make a <code>NuGet</code> of - but came to find that I also needed platform-specific functionality.</p>
  
  <p>So, I found <a href="https://stackoverflow.com/questions/55291602/how-does-one-create-a-project-to-create-a-nuget-package-for-xamarin-forms-suppor">this</a> stack overflow question - which indicated I could use a <code>Multiplatform Library</code>template instead. But here I encountered a <a href="https://stackoverflow.com/questions/57073400/dependencyservice-in-multiplatform-library-project">problem with DependencyService</a> - and a problem with <code>Custom Renderer</code> - effectively meaning that there was no way for the non-platform-specific to communicate with platform-specific code in the library.</p>
  
  <p>I also tried to edit the csproj file, examples: <a href="https://github.com/Cheesebaron/MultiTargetSample/blob/master/MultiTargetLib/MultiTargetLib.csproj" rel="nofollow noreferrer">A</a>, <a href="https://medium.com/corrado-cavalli/net-standard-and-multi-targeting-e96920b3fcfe" rel="nofollow noreferrer">B</a>, <a href="https://montemagno.com/converting-xamarin-libraries-to-sdk-style-multi-targeted-projects/" rel="nofollow noreferrer">C</a>. And by using the following csproj: </p>
  
  <pre><code>&lt;Project Sdk="MSBuild.Sdk.Extras/2.0.29"&gt;
    &lt;PropertyGroup&gt;
      &lt;TargetFrameworks&gt;netstandard2.0;Xamarin.ios10&lt;/TargetFrameworks&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup&gt;
      &lt;PackageReference Include="Xamarin.Forms" Version="4.1.0.581479" /&gt;
    &lt;/ItemGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>... the following solution is generated:</p>
  
  <p><a href="https://i.stack.imgur.com/5nfm9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5nfm9.png" alt="enter image description here"></a></p>
  
  <p>But in <code>Class1</code> the <code>Xamarin.iOS</code> nor <code>Xamarin.Forms.Platform.iOS</code> can be accessed in <code>Visual Studio for Mac</code>. And I recently checked and could see that it worked in <code>Visual Studio</code> on windows - using the same csproj.</p>
  
  <p>Is there any way to multitarget in <code>Visual Studio for Mac</code>?</p>
  
  <hr>
  
  <p><strong>Edit 1</strong>:
  I found an <a href="https://github.com/onovotny/MSBuildSdkExtras/issues/9" rel="nofollow noreferrer">issue</a> on <code>MSBuild.Sdk.Extras</code> on GitHub leading to this <a href="https://oren.codes/2017/08/29/use-all-tfms-with-sdk-style-projects-in-visual-studio-for-mac/" rel="nofollow noreferrer">post</a>. It seems a certain extension can be installed called <code>DotNetCoreSupportAnyTargetFramework.DotNetCoreSupportAnyTargetFramework_1.0</code>. But it won't be installed correctly in VSfM 8.1.5:</p>
  
  <p><a href="https://i.stack.imgur.com/RK11F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RK11F.png" alt="enter image description here"></a></p>
  
  <p>Trying it out in older VSfM I can't open project or create new ones - so I can't test to see if the extension works. It could be related to the following error message:</p>
  
  <p><a href="https://i.stack.imgur.com/zuHZ4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zuHZ4.png" alt="enter image description here"></a> </p>
  
  <p>that shows when opening the old VSfM.</p>
  
  <hr>
  
  <p><strong>Edit 2:</strong> After changing the order the target frameworks are given in - placing <code>Xamarin.ios10</code> first - the Xamarin.iOS and Xamarin.Forms.Platform.iOS became accessible - as mentioned by Matt Ward.</p>
  
  <p>However I can't add reference to the NetStandard Library to a Xamarin.Forms project to actually test the library:</p>
  
  <p><a href="https://i.stack.imgur.com/DvRXb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DvRXb.png" alt="enter image description here"></a></p>
  
  <p>And switching back to having netstandard placed first: </p>
  
  <blockquote>
    <p>Projects/MyStandardLibrary/MyStandardLibrary/MyButtonRender.cs(12,12): Error CS0246: The type or namespace name'ExportRendererAttribute' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (MyStandardLibrary) etc.</p>
  </blockquote>