0

I like the new 'msbuild pack' nuget package generation in VS2017. I would like to use it to generate a library that uses Xamarin.Mac to be consumed by Xamarin Mobile Mac projects. I tried

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>Xamarin.Mac</TargetFrameworks>
  </PropertyGroup>

</Project>

but I get

Severity    Code    Description Project File    Line    Suppression State
Error       Cannot infer TargetFrameworkIdentifier and/or TargetFrameworkVersion from TargetFramework='Xamarin.Mac'. They must be specified explicitly. Kumquat.Common.Mac  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets    84  

This example (https://github.com/Azure/azure-mobile-apps-net-client/blob/master/src/Microsoft.Azure.Mobile.Client/Microsoft.Azure.Mobile.Client.csproj) has

<TargetFrameworks>netstandard1.4;net45;MonoAndroid71;Xamarin.iOS10;uap10.0</TargetFrameworks>

However, when I try Xamarin.iOS10 on my end, I get a similar error. Is there something special I need to install on my machine to get Xamarin.* as Target Frameworks? I do have Xamarin installed. I have VS2017 (version 15.2).

tofutim
  • 22,664
  • 20
  • 87
  • 148

1 Answers1

0

The Microsoft.NET.Sdk doesn't support automatic inference for this target framework yet. As you can see in the example you linked, they add the required definitions later in the same project:

<PropertyGroup Condition=" '$(TargetFramework)' == 'Xamarin.iOS10' ">
  <TargetFrameworkIdentifier>Xamarin.iOS</TargetFrameworkIdentifier>
  <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
  <LanguageTargets>$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets</LanguageTargets>
  <DefineConstants>$(DefineConstants);PLATFORM_IOS;XAMARIN_AUTH_INTERNAL</DefineConstants>
</PropertyGroup>

The .NET Sdk has logic to infer TargetFrameworkIdentifier and TargetFrameworkVersion only for netstandard, netcoreapp and net at the moment (see the source)

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • I found this, and it was a lifesaver - https://github.com/onovotny/MSBuildSdkExtras - although I'm still seeing how I can get it to work in VSfM. – tofutim Jun 10 '17 at 07:02
  • The author also made a PR to the core .NET SDK but it hasn't been accepted yet https://github.com/dotnet/sdk/pull/889. All approaches do the same thing under the hood. – Martin Ullrich Jun 10 '17 at 07:04