TL DR
I am writing a Xamarin.Android application and want to refer to the NuGet package of my library, which is a DNX class library with dotnet . When I do this, the compiler issues a warning
The type 'DateTime' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, ...
and the IDE complains about messages like
Argument type 'System.DateTime [mscorlib, Version=2.0.5.0, Culture ...]' is not assignable to parameter type 'System.DateTime [mscorlib, Version=4.0.0.0, ...]'
although the builds succeed and the code works. How can I change this in the / project.json library?
Long story
Currently, we are transferring our projects to project.json types (Package, DNX, regardless of name). At the moment, we are launching integration with beta version 7 of Visual Studio and, in general, everything works fine. Now I want to reuse one of our model libraries in ASP.NET 5 and the Xamarin.Android project (from the NuGet feed).
Since we were completely out of luck with the class libraries targeting .NET 4.5.1 in the Xamarin project, I moved the model library to a DNX project targeting net45 , dnx45 and dotnet (in favor of dnxcore50 , as described here ), part of the framework in project.json is an
"frameworks": { "net45": { "frameworkAssemblies": { "mscorlib": "4.0.0.0", "System.Xml": "4.0.0.0", "System.Collections.Concurrent": "4.0.0.0" } }, "dnx45": { "frameworkAssemblies": { "mscorlib": "4.0.0.0", "System.Xml": "4.0.0.0", "System.Collections.Concurrent": "4.0.0.0" } }, "dotnet": { "dependencies": { "System.Collections": "4.0.0", "System.Linq": "4.0.0", "System.Runtime": "4.0.0", "System.Reflection": "4.0.0", "System.Runtime.Extensions": "4.0.0", "System.Threading": "4.0.0", "System.Text.RegularExpressions": "4.0.0", "System.Text.Encoding": "4.0.0", "System.Collections.Concurrent": "4.0.0" } } },
Although this article suggests using net45 as the target for monoandroid51 projects, Android is used instead of the dotnet library when I add the NuGet package to it.
Then package.json contains
<package id="My.Awesome.Lib" version="1.2.3-foo9" targetFramework="monoandroid51" />
and .csproj is available
<Reference Include="My.Awesome.Lib, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\packages\My.Awesome.Lib.1.2.3-foo9\lib\dotnet\My.Awesome.Lib.dll</HintPath> <Private>True</Private> </Reference>
This still works if I donβt have version numbers above 4.0.0 in the part of dependencies and basically burns when I do this, however the following
However , when I create the project, I will get a compiler warning
1>C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1706,3): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
immediately after the link to the library. In Visual Studio, whenever I pass a value from an Android project to one of the library types, I get red squiggly lines with a message containing
The type 'DateTime' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, ...
and
Argument type 'System.DateTime [mscorlib, Version=2.0.5.0, Culture ...]' is not assignable to parameter type 'System.DateTime [mscorlib, Version=4.0.0.0, ...]'
which makes perfect sense, since Xamarin BCL is marked as version v2.0.50727 , while my library is v4.0.30319 .
Now I am wondering if I need to focus on some kind of PCL or if something else is missing for me.