Bug 52110 - ProjectReference to multi-targeted project fails build
Summary: ProjectReference to multi-targeted project fails build
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Android ()
Version: 4.3.0 (C9)
Hardware: PC Windows
: Normal normal
Target Milestone: 4.3.0 (C9)
Assignee: Bugzilla
Depends on:
Reported: 2017-01-31 18:29 UTC by adamhewitt
Modified: 2017-03-03 21:34 UTC (History)
5 users (show)

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

Reproduction (9.95 KB, application/x-zip-compressed)
2017-02-03 16:29 UTC, adamhewitt

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 on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description adamhewitt 2017-01-31 18:29:09 UTC
The end result of this structure is MSBuild looking for the target "GetBuiltProjectOutputRecursive" in all referenced projects, and failing to find the target.

It appears (Xamarin.Common.targets) that the build system collects outputs by calling MSBuild on each project, but this doesn't then load the project correctly when it is setup with multiple platform targets. "TargetPlatform" not being set, it then doesn't resolve the appropriate Xamarin imports.

I have included a reproduction project. This is on VS2017-RC3 with XVS I presume it happens on iOS as well, but I haven't gotten far enough to need to prove that.
Comment 1 adamhewitt 2017-01-31 18:32:50 UTC
I forgot to mention, "Android.targets" in the project is the workaround that I'm trying out. (It works for this sample, haven't yet tried in my larger project) 

It's not unlike other project.json/csproj coexistence workarounds in that it ensures TargetFramework is set when calling to the bigger project.

EDIT ABOVE: I called out "TargetPlatform" not being set in calling the project reference, but writing this addendum I realized I meant to say TargetFramework.
Comment 2 Joaquin Jares 2017-02-01 17:19:59 UTC
I'm trying a repro to see if I understand properly.
Comment 3 Joaquin Jares 2017-02-02 18:16:03 UTC
@Adam while I try my own repro, you mention a reproduction project but I don't see any attachments in the bug.
Comment 4 adamhewitt 2017-02-03 16:29:46 UTC
Created attachment 19715 [details]

Here is a reproduction. While I mentioned using a .targets file to work around the build error, that ultimately raised too many other hassles. This includes a better proposed resolution in App2.csproj.
Comment 5 Joaquin Jares 2017-02-14 13:28:51 UTC
I lost track of this, sorry. I'll check it again. Thanks for the repro!
Comment 6 Daniel Cazzulino 2017-02-14 14:39:04 UTC
Fixed in 8bad02596fc110161d982c1620bfc118364749d2.

Will be included in RTW.
Comment 7 Daniel Cazzulino 2017-02-14 14:41:27 UTC
A manual workaround in the meantime is to modify the file at C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Microsoft.Common.Targets\ImportAfter\Xamarin.Common.targets with the following:

	<Target Name="GetBuiltProjectOutputRecursive" Returns="@(AllBuiltProjectOutputs)" DependsOnTargets="AssignProjectConfiguration">
			Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)" 
			<Output TaskParameter="TargetOutputs" ItemName="_RecursiveBuiltProjectOutputs" />