繁体   English   中英

在DNX项目中,我如何定位Xamarin Android?

[英]In a DNX project, how can I target for Xamarin Android?

TL; DR

我正在编写一个Xamarin.Android应用程序,并希望引用我的库的NuGet包,这是一个以dotnet为目标的DNX类库。 当我这样做时,编译器会发出警告

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, ...

IDE抱怨像这样的消息

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, ...]'

虽然构建成功并且代码有效。 如何在库/ project.json更改它?

很长的故事

在工作中,我们目前正在将项目移植到project.json -type(Package,DNX,无论名称是什么)。 目前,我们正在运行beta 7 Visual Studio集成,一般来说,一切正常。 我现在想要在ASP.NET 5和Xamarin.Android项目(来自NuGet提要)中重用我们的模型库之一。

因为我们曾与在Xamarin项目针对.NET 4.5.1类库绝对没有运气我迁移模型库的DNX项目瞄准net45dnx45dotnet (赞成dnxcore50 ,描述在这里 ),在该框架的部分project.json正在

"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"
    }
  }
},

虽然本文建议使用net45作为monoandroid51项目的目标,但每当我向其添加NuGet包时,Android项目都会引用dotnet库。

然后package.json包含

<package id="My.Awesome.Lib" version="1.2.3-foo9" targetFramework="monoandroid51" />

.csproj

<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>

到目前为止,除非我在dependencies部分中的版本号高于4.0.0 ,并且基本上在我做的时候燃烧,但是

但是当我构建项目时,我会得到编译器警告

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.

在图书馆参考之后。 在Visual Studio中,每当我将一个值从Android项目传递给其中一个库类型时,我都会得到一条带有消息说明的红色波浪线

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, ...

以及

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, ...]'

这是完全v4.0.30319 ,因为Xamarin BCL标记为运行时版本v2.0.50727 ,而我的库是v4.0.30319

我现在想知道我是否需要针对某些PCL某些东西,或者是否还有其他东西我不知道。

这不是YET支持。 为了支持这种情况,还需要更新以负责正在考虑简化参考的新标记。

在未来,你只需要使用netstandard1.4而不是dnxcore50 ,你就可以运行所有内容并与Xamarin兼容。

.NET标准平台

这是事情的发展方向。 简化定位多个平台的疯狂。 这是我获得netstandard*绰号的地方,当然,直到它被释放......这仍然有可能改变。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM