Bug 53261 - Cannot build Xamarin.iOS project with new dotnet cli tools
Summary: Cannot build Xamarin.iOS project with new dotnet cli tools
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild ()
Version: XI 10.8 (d15-1)
Hardware: PC Mac OS
: Low enhancement
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-03-11 16:38 UTC by Andrey Verbin
Modified: 2017-04-03 17:19 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 53261 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Andrey Verbin 2017-03-11 16:38:12 UTC
I migrated my Xamarin.iOS project to latest msbuild csproj project file format with 'dotnet migrate'. After that I cannot do 'dotnet build' anymore. Build fails with following error:

>/usr/local/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.TargetFrameworkInference.targets(84,5): error : Cannot infer TargetFrameworkIdentifier and/or TargetFrameworkVersion from TargetFramework='xamarinios10'. They must be specified explicitly.

I found that Visual Studio Mac works so much better with new project files compared to project.json/package.config style projects.  Improvement is very significant, to the point that I'd rather use Visual Studio Mac instead of VMWare + Visual Studio 2015 combination. The only things which stops me is this issue. I hope there is quick solution or workaround for this.

Thanks
Comment 1 Matt Ward 2017-03-11 18:29:50 UTC
This is not supported currently. I believe we would need to add custom MSBuild targets to properly support Xamarin.iOS with the new Sdk style project file format. We would probably want to have a special Xamarin.iOS sdk that is imported into the project.
Comment 2 Jeffrey Stedfast 2017-03-13 17:43:18 UTC
How does this dotnet tool work? Our Xamarin.iOS.CSharp.targets already set the TargetFrameworkIdentifier and TragetFrameworkVersion:

<TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">Xamarin.iOS</TargetFrameworkIdentifier>
<TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">v1.0</TargetFrameworkVersion>

What else needs to be done?
Comment 3 Matt Ward 2017-03-13 18:27:07 UTC
Probably want to chat with mhutch about what the plan is for this. The new style .NET Core projects look like the following:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>
</Project>

So the files added to the project are defined with implicitly imported MSBuild files based on the Sdk being imported, which in the above case is Microsoft.NET.Sdk.

So to do this fully we would probably want to do something like:

<Project Sdk="Xamarin.iOS">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>xamarinios10</TargetFramework>
  </PropertyGroup>
</Project>

Which would not work with the existing Xamarin.iOS MSBuild targets since they do not define any file globs.

If you are not that concerned about having a simplified MSBuild project file you can basically take an existing Xamarin.iOS project and make two changes to it:

1) Change Project element to use an Sdk attribute:

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

2) In the global property group disable the default file globbing rules:

<EnableDefaultCompileItems>false</EnableDefaultCompileItems>

All files would need to be added to the project the same as before. Unless you work out some file globs that can be added to the project.

You can then, after setting the MSBuildSDKsPath environment variable to point to the .NET Core SDK, compile from the command line using MSBuild. However within Xamarin Studio the project is not currently treated as a .NET Core project.
Comment 4 danmiser 2017-03-29 23:00:00 UTC
I think this is impacting more than just .NET Core. 

I have a xamarinios10 csproj that I use to package and publish via nuget. The pack command is erroring out when executed on this csproj.

This machine has never had VS2015 on it. Right now, I'm forced to make my changes, go to my VM that has VS2015 on it, fetch the changes and nuget pack and push from there.

If I'm missing something, let me know, but I'm thinking this needs to be solved with the same type of fix for this thread.

I have a thread going here about the issues I'm facing:
https://forums.xamarin.com/discussion/comment/261947
Comment 5 Jeffrey Stedfast 2017-04-03 15:42:46 UTC
@Matt Ward:

Ugh, file globs are not going to work well for Xamarin.iOS :(


@Dan Miser:

I honestly don't understand how `nuget pack` has anything to do with this feature request?
Comment 6 Jeffrey Stedfast 2017-04-03 17:09:15 UTC
@Andrey: for now, I would recommend not migrating your Xamarin.iOS, Android or Mac projects using `dotnet migrate`.

The new project format is not supported by any of those project types.
Comment 7 Mikayla Hutchinson [MSFT] 2017-04-03 17:19:48 UTC
This is a bug in `dotnet migrate`. You cannot migrate iOS projects the same way as .NET Core projects, and it's creating an invalid project.

We would definitely like to support the new `Sdk` style projects for Xamarin.iOS at some point. However, it would involve building an iOS MSBuild SDK, rewriting our VS project system using CPS, and designing a migration system for the properties and items in iOS projects. It would also break project format compatibility with VS2015. We're looking into it, but it probably won't be any time soon for the aforementioned reasons.

FWIW you can use <PackageReference> without migrating, at least on Mac.