Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transitive nuget dependencies are not handled with netstandard libraries #3949

Closed
chamons opened this issue Apr 17, 2018 · 7 comments
Closed
Labels
enhancement The issue or pull request is an enhancement iOS Issues affecting iOS macOS Issues affecting macOS
Milestone

Comments

@chamons
Copy link
Contributor

chamons commented Apr 17, 2018

A netstandard library that depends on nuget libraries will not be correctly resolved unless the XM or XI library in question also resolves those libraries independently.

Steps to Reproduce

  1. TestNugetProjectOverRefs.zip
  2. Build XM (TestNugetProjectOverRefs) project and run. Note runtime failure
  3. Build XI (TestNugetProjectOverRefs.iOS) project. It will fail in linking.

Expected Behavior

The XI and XM library to resolve the nuget required by the netstd library.

Actual Behavior

The "transitive" dependency of a dependency is not resolved correctly.

Environment

https://gist.github.com/chamons/a1fb655991f9bb749168b406e7544cce

Build Logs

https://gist.github.com/chamons/f66954a712614afa70058b63e909041a

Example Project (If Possible)

@chamons chamons added bug If an issue is a bug or a pull request a bug fix macOS Issues affecting macOS iOS Issues affecting iOS labels Apr 17, 2018
@spouliot
Copy link
Contributor

    Dependency "Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed".
        Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

msbuild does not resolve it so it's never given to mmp (or mtouch)

@chamons
Copy link
Contributor Author

chamons commented Apr 17, 2018

Well then it's an msbuild issue apparently. This "should" work I believe. @jstedfast @radical ?

@mandel-macaque mandel-macaque added this to the Future milestone Apr 18, 2018
@chances
Copy link

chances commented Jun 9, 2018

Any update on this issue?

Should I just add my transitive dependencies as references in my root project as a workaround? Doing this works with my NuGet dependencies.

@chamons
Copy link
Contributor Author

chamons commented Jun 11, 2018

@chances - I believe that is the best work around until this is sorted out. There is no update currently.

@rolfbjarne rolfbjarne added enhancement The issue or pull request is an enhancement and removed bug If an issue is a bug or a pull request a bug fix labels Sep 11, 2018
@rolfbjarne
Copy link
Member

So after some investigation (for a developer community issue), it seems this is kind of the expected behavior: dependencies of .netstandard projects don't flow to the referencing ("old-style") project. This behavior is explained in dotnet/sdk#901.

The fix seems to be to migrate your main project to a PackageReference project, which is fairly simple: https://stackoverflow.com/a/49266856/183422.

For extensions, this also needs an additional fix (the fix for #4237), which should be released to stable together with our iOS 12 supported release fairly soon.

Leaving open so that we can write tests (can't do it quite yet, since we need to build/test with msbuild, which requires 2018-06 to get a version that supports our needs).

rolfbjarne added a commit to rolfbjarne/xamarin-forms-samples that referenced this issue Apr 1, 2019
This fixes a build problem where the iOS project isn't passed the reference to
the referenced .NET Standard project's nuget reference, and the linker ends up
complaining that it can't find the NuGet:

    MTOUCH : error MT2001: Could not link assemblies. Reason: Error while processing references of 'TodoRESTiOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' [/xamarin-forms-samples/WebServices/TodoREST/iOS/TodoREST.iOS.csproj]
      --- inner exception (TaskId:143)
      Mono.Linker.LoadException: Error while processing references of 'TodoRESTiOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' (TaskId:143)

Reference: xamarin/xamarin-macios#3949
conceptdev pushed a commit to xamarin/xamarin-forms-samples that referenced this issue Apr 8, 2019
This fixes a build problem where the iOS project isn't passed the reference to
the referenced .NET Standard project's nuget reference, and the linker ends up
complaining that it can't find the NuGet:

    MTOUCH : error MT2001: Could not link assemblies. Reason: Error while processing references of 'TodoRESTiOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' [/xamarin-forms-samples/WebServices/TodoREST/iOS/TodoREST.iOS.csproj]
      --- inner exception (TaskId:143)
      Mono.Linker.LoadException: Error while processing references of 'TodoRESTiOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' (TaskId:143)

Reference: xamarin/xamarin-macios#3949
@chamons
Copy link
Contributor Author

chamons commented Oct 12, 2020

So I'm still seeing this problem on resolving native libraries inside nugets.

In this example:

CogServTest.zip

I have two projects:

  • CogServTest - A XI project
  • NetLib - A netstd library

NetLib has a reference to Microsoft.CognitiveServices.Speech nuget. If the XI project does not, it incorrectly resolves:

~/.nuget/packages/microsoft.cognitiveservices.speech/1.13.0/runtimes/win-x64/native/Microsoft.CognitiveServices.Speech.core.dll

NOT

~/.nuget/packages/microsoft.cognitiveservices.speech/1.13.0//build/Xamarin.iOS/libMicrosoft.CognitiveServices.Speech.core.a

Once I add the nuget to the main XI project, it starts working.

@rolfbjarne
Copy link
Member

This is solved in .NET.

@rolfbjarne rolfbjarne closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Oct 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement The issue or pull request is an enhancement iOS Issues affecting iOS macOS Issues affecting macOS
Projects
None yet
Development

No branches or pull requests

5 participants