Bug 40094 - Create default Xamarin project in VS -> xbuild project reference error, with missing GUID
Summary: Create default Xamarin project in VS -> xbuild project reference error, with ...
Status: RESOLVED FIXED
Alias: None
Product: Tools
Classification: Mono
Component: xbuild ()
Version: unspecified
Hardware: PC Windows
: High major
Target Milestone: ---
Assignee: Ankit Jain
URL:
Depends on:
Blocks:
 
Reported: 2016-04-05 03:09 UTC by Bret Johnson [MSFT]
Modified: 2016-04-07 01:26 UTC (History)
8 users (show)

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


Attachments
Repro project (274.05 KB, application/zip)
2016-04-06 00:32 UTC, Mikayla Hutchinson [MSFT]
Details


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 GitHub or 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:
Status:
RESOLVED FIXED

Description Bret Johnson [MSFT] 2016-04-05 03:09:12 UTC
In VS 2015, do a File / New Project for a Xamarin Blank App (Native Portable).  Now try to build the project on a Mac, using xbuild.   That happens, in for example, when you use the new Xamarin iOS build task in Visual Studio Team Services.

Result: xbuild gets an error on the build complaining about a missing GUID in the project reference, like the following:


Errors:
/Users/vso112383/vsts-agent/_work/2/s/HelloWorld/Xamarin.HelloWorld.sln (default targets) ->
(Build target) ->
/Users/vso112383/vsts-agent/_work/2/s/HelloWorld/HelloWorldApp/HelloWorldApp.iOS/HelloWorldApp.iOS.csproj (default targets) ->
/Library/Frameworks/Mono.framework/Versions/4.2.3/lib/mono/4.5/Microsoft.Common.targets (AssignProjectConfiguration target) ->
       /Library/Frameworks/Mono.framework/Versions/4.2.3/lib/mono/4.5/Microsoft.Common.targets: error : Project reference '../HelloWorldApp/HelloWorldApp.csproj' has invalid or missing guid for metadata 'Project'.



As a workaround, you can edit the iOS csproj file and add the PCL project's guid to the reference manually, adding a GUID line as shown here:

    <ProjectReference Include="..\HelloWorld\HelloWorld.csproj">
      <Project>{E423155C-0114-4465-9A90-3369AEACA218}</Project>
      <Name>HelloWorld</Name>
    </ProjectReference>

That makes the build work, but of course shouldn't be necessary.

Likely we should fix xcode to work in this scenario.

This was a customer reported issue, from an email thread that Mikayla and myself were cc'ed on.  It's easily reproduced.
Comment 1 Mikayla Hutchinson [MSFT] 2016-04-05 22:29:11 UTC
This has already been fixed in cycle7 (Mono 4.4.x) which is currently on the alpha update channel.

https://github.com/mono/mono/commit/5977060b42e72d2dc8494a10f743eca813255eff

I constructed a test case and verified that it works correctly with the xbuild in in Mono 4.4.0.43.

On inspection the AssignProjectConfiguration code in MSBuild, it appears that MSBuild used to require a GUID in project references, but it was changed to lookup by path when the GUID is are not present. xbuild doesn't have this fallback, but in the case described in the bug this doesn't seem to be a problem in practice. We'll be moving to MSBuild soon so this will be a moot point.
Comment 2 Mikayla Hutchinson [MSFT] 2016-04-05 23:38:04 UTC
Looks like I spoke too soon.

I tried a more complex example, and even with the fix, it errors out.

                        Task "AssignProjectConfiguration"
                                Using task AssignProjectConfiguration from Microsoft.Build.Tasks.AssignProjectConfiguration, Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
/Library/Frameworks/Mono.framework/Versions/4.4.0/lib/mono/4.5/Microsoft.Common.targets:  warning : Project reference '../App1/App1.csproj' could not be resolved.

We need to do as MSBuild does and write the full file path for each project into CurrentSolutionConfigurationContents, and have AssignProjectConfiguration use the path as a fallback if the GUID is not set.
Comment 3 Mikayla Hutchinson [MSFT] 2016-04-05 23:49:20 UTC
NOTE: I bumped priority on this because our VS extension is creating projects without the GUID in the project references.

This appears to be fixed in the C7 version of the extension (https://github.com/xamarin/XamarinVS/commit/9d5af3a1a1ef8d91fa11b2cf8f2eb6be729ef23d) but there will likely be many existing projects that hit this bug in xbuild.
Comment 4 Mikayla Hutchinson [MSFT] 2016-04-06 00:32:55 UTC
Created attachment 15619 [details]
Repro project
Comment 5 Mikayla Hutchinson [MSFT] 2016-04-06 00:34:41 UTC
To repro:

    nuget restore
    xbuild

Expected result:

    App1.WinPhone.csproj fails

Actual result:

    App1.WinPhone.csproj fails
    App1.Droid.csproj fails
Comment 6 Mikayla Hutchinson [MSFT] 2016-04-07 01:26:49 UTC
This has been fixed in master and the C7 (4.4.0) branch:

https://github.com/mono/mono/commit/890f40d7ad1d68ea5ff86ffdd3f6829dbd86b3ab

https://github.com/mono/mono/commit/149a844478bfb2f7a7f0739f51e1aa0ec77262fc