Bug 60165 - PackageReference nuget references resolve ref over lib incorrectly
Summary: PackageReference nuget references resolve ref over lib incorrectly
Status: CONFIRMED
Alias: None
Product: Tools
Classification: Mono
Component: msbuild ()
Version: 5.4 (2017-06)
Hardware: PC Mac OS
: High critical
Target Milestone: 15.4 SR2
Assignee: Ankit Jain
URL:
Depends on:
Blocks:
 
Reported: 2017-10-12 22:02 UTC by Chris Hamons
Modified: 2017-10-19 14:37 UTC (History)
9 users (show)

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


Attachments
Prebuilt nuget (15.56 KB, application/zip)
2017-10-18 15:55 UTC, Chris Hamons
Details
msbuild.log (512.26 KB, text/plain)
2017-10-19 09:08 UTC, Ankit Jain
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 for Bug 60165 on GitHub or Developer Community 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: GitHub Markdown or Developer Community HTML
  • 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 Chris Hamons 2017-10-12 22:02:25 UTC
- Clone https://github.com/chamons/filed-bug-test-cases/tree/master/XMNuget
- Build with d15-4 and run
- Error with

Could not find `System.ValueTuple` referenced by assembly `Microsoft.CodeAnalysis, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35`.
Could not find `System.ValueTuple` referenced by assembly `Microsoft.CodeAnalysis.CSharp, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35`.
Could not find `System.ValueTuple` referenced by assembly `XMNuget, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null`.

Since mono is rejecting the ref version being resolved.

Workaround
- Manually copy in the lib version
Comment 1 Chris Hamons 2017-10-13 15:00:17 UTC
Build Log: https://gist.github.com/chamons/85d68df484c5153baafdb87437fca5d1
Comment 2 Chris Hamons 2017-10-13 18:33:20 UTC
The issues extends beyond Xamarin.Mac. I have a better repro:

https://github.com/chamons/filed-bug-test-cases/tree/master/XI_nuget_libref

where I created a nuget with lib and ref versions (only differing based on the string returned.

If I use "normal" package refs, every single test (Console, XI, XM Full, XM Modern) return the lib version. However, if I swap to PackageReference they all resolve refs instead.
Comment 3 Aaron Bockover [MSFT] 2017-10-13 21:35:01 UTC
I ran into this again with System.Runtime.Loader (a dependency of Microsoft.CodeAnalysis.Scripting) - the assembly that was referenced/copied into the app bundle was from `ref` and not `lib` (in the NuGet package).
Comment 4 Chris Hamons 2017-10-13 21:55:01 UTC
It doesn't _have_ to be SR2 but we should consider it. 15.5 for sure (no 15.5 in milestone list).
Comment 5 Chris Hamons 2017-10-16 15:56:34 UTC
There is some rather understandable confusion over my repro, with it's "thrown together while trying to reproduce the issue" layout.

I will be cleaning it up shortly.
Comment 6 Chris Hamons 2017-10-16 17:23:59 UTC
Ok, I cleaned it up. The previous links no longer work, but I wrote a makefile to automate most of the repro:

https://github.com/chamons/filed-bug-test-cases/tree/master/nuget_lib_ref

Running make will generate a nuget showing the issue, then stop for you to copy it into a local nuget feed (so nuget restore will work). It will then build XI/XM/Console apps both using package references and normal references and run non-XI samples (prompting you to test those by hand).

Each test will print "lib" or "ref" depending on which library you have loaded.
Comment 7 Ankit Jain 2017-10-18 05:15:45 UTC
This keeps failing for me while trying to find the `TestLib` package. I added it with `nuget add <nupkg> -Source /tmp/local` and have a local source added with `nuget sources add -Name local  -Source /tmp/local`.

Can you reproduce this with XM master? specifically one that includes https://github.com/xamarin/xamarin-macios/commit/f79f2e44241ebfd8d55fff9596f88ba4adc43e50 .

The `lib` files become available via the `@(ReferenceCopyLocalPaths)`. Nuget targets populate that accordingly. And for reference resolution and compiling, `ref` paths are used. If you are not getting the expected paths in ``@(ReferenceCopyLocalPaths)`, then maybe we missed something.
Comment 8 Marek Safar 2017-10-18 15:31:49 UTC
Can you summarize reliable steps for Console App ?

Using your github repo I get 

rm -rf nuget/
rm -f TestLib/MyClass.cs
rm -f TestLib.1.0.0.nupkg
msbuild TestLib/TestLib.sln /t:clean /v:quiet /nologo
msbuild Sample.StandardRef/Sample.sln /t:clean /v:quiet /nologo
sed 's/BUILD_TYPE/lib/g' TestLib/MyClass.cs.in > TestLib/MyClass.cs
cp -r nuget.in/ nuget/
msbuild TestLib/TestLib.sln /v:quiet /nologo
cp TestLib/TestLib.Basic/bin/Debug/TestLib.dll nuget/lib/net47/TestLib.dll
cp: nuget/lib/net47/TestLib.dll: No such file or directory
make: *** [TestLib.1.0.0.nupkg] Error 1
Comment 9 Chris Hamons 2017-10-18 15:55:09 UTC
Created attachment 25357 [details]
Prebuilt nuget
Comment 10 Chris Hamons 2017-10-18 15:57:57 UTC
I've attached the nuget that build produces. You should be able to drop it your local nuget feed location and run:

make sample-packageref
make sample-standard

or just 

	nuget restore Sample.PackageRef/Sample.sln
	msbuild Sample.PackageRef/Sample.sln /v:quiet /nologo
	mono ./Sample.PackageRef/Sample.Console/bin/Debug/Sample.Console.exe

	nuget restore Sample.StandardRef/Sample.sln
	msbuild Sample.StandardRef/Sample.sln /v:quiet /nologo
	mono ./Sample.StandardRef/Sample.Console/bin/Debug/Sample.Console.exe

or even build just the console csproj.

I would be rather interested in a build log (no quiet) to see why it isn't building on your machine though...
Comment 11 Marek Safar 2017-10-19 08:45:43 UTC
make sample-packageref fails with


Errors in filed-bug-test-cases-master/nuget_lib_ref/Sample.PackageRef/Sample.MacModern/Sample.MacModern.csproj
    NU1202: Package TestLib 1.0.0 is not compatible with xamarinmac20 (Xamarin.Mac,Version=v2.0). Package TestLib 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
    NU1202: Package TestLib 1.0.0 is not compatible with xamarinmac20 (Xamarin.Mac,Version=v2.0) / win. Package TestLib 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
    NU1202: Package TestLib 1.0.0 is not compatible with xamarinmac20 (Xamarin.Mac,Version=v2.0) / win-x64. Package TestLib 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
    NU1202: Package TestLib 1.0.0 is not compatible with xamarinmac20 (Xamarin.Mac,Version=v2.0) / win-x86. Package TestLib 1.0.0 supports: net40 (.NETFramework,Version=v4.0)

Errors in nuget_lib_ref/Sample.PackageRef/Sample.iOS/Sample.iOS.csproj
    NU1202: Package TestLib 1.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0). Package TestLib 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
    NU1202: Package TestLib 1.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win. Package TestLib 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
    NU1202: Package TestLib 1.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win-x64. Package TestLib 1.0.0 supports: net40 (.NETFramework,Version=v4.0)
    NU1202: Package TestLib 1.0.0 is not compatible with xamarinios10 (Xamarin.iOS,Version=v1.0) / win-x86. Package TestLib 1.0.0 supports: net40 (.NETFramework,Version=v4.0)



make sample-standard fails with

Program.cs(9,29): error CS0103: The name 'TestLib' does not exist in the current context [/Users/marek/Downloads/filed-bug-test-cases-master/nuget_lib_ref/Sample.StandardRef/Sample.Console/Sample.Console.csproj]
Comment 12 Ankit Jain 2017-10-19 09:07:39 UTC
The build was failing to copy files because of missing `nuget/*/net47` and `nuget/*/xamarinios10`. Then it failed with the same error as Marek. Attaching the diag log.
Comment 13 Ankit Jain 2017-10-19 09:08:29 UTC
Created attachment 25369 [details]
msbuild.log
Comment 14 Ankit Jain 2017-10-19 09:11:40 UTC
Also, I changed `nuget restore` for `sample-packageref` to  `msbuild /t:Restore Sample.PackageRef/Sample.sln`.
Comment 15 Ankit Jain 2017-10-19 09:37:59 UTC
Sorry, the log is not about Marek's error. I am not getting that one now! Starting afresh it was complaining about some missing directories, so I had to create `mkdir nuget.in/{lib,ref}/{net47,xamarinmac20,xamarinios10}` . And then I get the error in the attached log.
Comment 16 Ankit Jain 2017-10-19 14:04:34 UTC
Ok, so the error in my earlier attached log file was because XCode's components needed to be installed after the last update! Now, I can reproduce the issue and see:

These all should be lib but are ref (since things do not work)
mono ./Sample.PackageRef/Sample.Console/bin/Debug/Sample.Console.exe
ref
./Sample.PackageRef/Sample.MacFull/bin/Debug/Sample.MacFull.app/Contents/MacOS/Sample.MacFull
ref
./Sample.PackageRef/Sample.MacModern/bin/Debug/Sample.MacModern.app/Contents/MacOS/Sample.MacModern
ref
Comment 17 Chris Hamons 2017-10-19 14:37:43 UTC
Moving to confirmed now that Ankit can repro.

Apologies about missing the mkdir command in the makefile.