Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to solve references conflict between Xamarin Android and NugetPackage(Automapper)?

$
0
0

Hello all. I spent 2 days googling, trying to resolve conflict situation with dll versioning in Xamarin. I saw a lot of posts with identical issues (just different NuGet packages) but as I saw, no concrete solution anywhere. I will try to summarize briefly here.

I am using Xamarin for android (Not Xamarin Forms). This project references my .NET standard 2.0 (.NET Core) project that contains all core logic. I Installed Automapper via NuGet in my core project and suddenly I have build warning that describes conflict. Conflict is that Xamarin for android (Mono) uses Microsoft.Csharp.dll version 2.0.5.0 and Auto mapper which is in referenced Core project uses Microsoft.Csharp.dll 4.0.0.0

Here is the output from build process related to mentioned:

    There was a conflict between "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". (TaskId:131)
2>      "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not. (TaskId:131)
2>      References which depend on "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll]. (TaskId:131)
2>          C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll (TaskId:131)
2>            Project file item includes which caused reference "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll". (TaskId:131)
2>              Microsoft.CSharp (TaskId:131)
2>      References which depend on "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" []. (TaskId:131)
2>          C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll (TaskId:131)
2>            Project file item includes which caused reference "C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll". (TaskId:131)         C:\Users\missa\.nuget\packages\automapper\7.0.1\lib\netstandard2.0\AutoMapper.dll (TaskId:131)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.

So, build process has chosen older version from Xamarin (this is confirmed because I extracted APK to see which dll is physically inside and found 2.0.5.0)

Now, the summary of the questions is:

  1. If I leave the warning and accept current situation, I will have Microsoft.Csharp.dll 2.0.5.0 in the package. I suppose Android project is OK with this, since it originally references this version, but how will AutoMapper behave since it is built with 4.0.0.0 reference? If it uses some new features, and old version doesn't have them, it is not good.
  2. Can I somehow force Xamarin to use Microsoft.Csharp.dll 4.0.0.0 since I don't see this reference directly (Mono reference is using it)? I can't use binding redirect from app.config since Xamarin for Android doesn't support app.config. Even if there is a way somehow, is it smart solution since maybe Microsoft.Csharp 4.0.0.0 is not backward compatible with 2.0.5.0
  3. If 1 or 2 are not good solutions, is it possible somehow (codebase path or something else) to make the situation to have both versions and that every component references its original version?

This issue with AutoMapper is just an example, but basically this case can happen with any other package. I saw that it was actual with NewtonJson and is solved in new version of NewtonJson package where reference to Miscrosoft.Cshap.dll is removed.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>