简体   繁体   English

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

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

TL;DR TL; DR

I'm writing a Xamarin.Android app and want to reference the NuGet package of a library of mine that is a dotnet -targeted DNX class library. 我正在编写一个Xamarin.Android应用程序,并希望引用我的库的NuGet包,这是一个以dotnet为目标的DNX类库。 When I do this, the compiler spits out the 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 with messages like 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, ...]'

although the builds succeed and the code works. 虽然构建成功并且代码有效。 How can I change that in the library / the project.json ? 如何在库/ project.json更改它?

Long story 很长的故事

At work we're currently porting our projects to project.json -type ones (Package, DNX, whatever the name is). 在工作中,我们目前正在将项目移植到project.json -type(Package,DNX,无论名称是什么)。 At the moment, we're running the beta 7 Visual Studio integration and, in general, everything works out just fine. 目前,我们正在运行beta 7 Visual Studio集成,一般来说,一切正常。 I now want to reuse one of our model libraries within an ASP.NET 5 and a Xamarin.Android project (from a NuGet feed). 我现在想要在ASP.NET 5和Xamarin.Android项目(来自NuGet提要)中重用我们的模型库之一。

Since we had absolutely no luck with class libraries targeting .NET 4.5.1 in the Xamarin project I migrated the model library to a DNX project targeting net45 , dnx45 and dotnet (in favor of dnxcore50 , as described here ), the frameworks part in the project.json being 因为我们曾与在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"
    }
  }
},

Although this article suggests using net45 as a target for monoandroid51 projects, the dotnet library is instead referenced by the Android project whenever I add the NuGet package to it. 虽然本文建议使用net45作为monoandroid51项目的目标,但每当我向其添加NuGet包时,Android项目都会引用dotnet库。

The package.json then contains 然后package.json包含

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

and the .csproj there has .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>

This works out so far unless I have version numbers higher than 4.0.0 in the dependencies part and basically combusts when I do, however the following 到目前为止,除非我在dependencies部分中的版本号高于4.0.0 ,并且基本上在我做的时候燃烧,但是

However when I build the project, I'll get the 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.

right after the library reference. 在图书馆参考之后。 Within Visual Studio, whenever I pass a value from the Android project to one of the library types, I'll get the red squiggly lines with a message stating 在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, ...

as well as 以及

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 the Xamarin BCL is labeled as runtime version v2.0.50727 , whereas my library is v4.0.30319 . 这是完全v4.0.30319 ,因为Xamarin BCL标记为运行时版本v2.0.50727 ,而我的库是v4.0.30319

I'm now wondering if I need to target some PCL something or if there is something else I'm missing. 我现在想知道我是否需要针对某些PCL某些东西,或者是否还有其他东西我不知道。

This is not YET supported. 这不是YET支持。 To support this scenario, will need to also be updated to take in charge the new monikers that are being thought about to simplify the references. 为了支持这种情况,还需要更新以负责正在考虑简化参考的新标记。

In the future, you would just target netstandard1.4 instead of dnxcore50 and you would have everything running and compatible with Xamarin. 在未来,你只需要使用netstandard1.4而不是dnxcore50 ,你就可以运行所有内容并与Xamarin兼容。

.NET Standard Platform .NET标准平台

This is where things will be going. 这是事情的发展方向。 To simplify the madness of targeting multiple platforms. 简化定位多个平台的疯狂。 This is where I got my netstandard* moniker and of course, until it hits release... this is still subject to change. 这是我获得netstandard*绰号的地方,当然,直到它被释放......这仍然有可能改变。

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

相关问题 如何在android项目属性中启用调试(Xamarin Android) - How can i enable debug in android project properties (Xamarin Android) 我无法使用Asp.Net MVC 6和DNX启动项目 - I can not start the project with Asp.Net MVC 6 and DNX 如何针对dnx451在dnx50项目上运行测试? - How do I run tests on my dnx50 project against dnx451? 无法在Xamarin Project中取消选中Windows 8 Target - Can't Uncheck Windows 8 Target in Xamarin Project 如何使用config.json为Visual Studio 2015 / DNX项目设置特定于环境的变量? - How can I use config.json to set environment-specific variables for a Visual Studio 2015/DNX project? 如何诊断dnx中缺少的依赖项(或其他加载程序失败)? - How can I diagnose missing dependencies (or other loader failures) in dnx? 如何使用最新的NuGet软件包支持库更新xamarin android项目? - How can I update my xamarin android project with the latest NuGet packages support libraries? 如何在 Xamarin android 中使用 PopupWindow? - How can I use PopupWindow in Xamarin android? 对Xamarin项目Android框架版本感到困惑(最低vs目标) - Confused about Xamarin project Android framework versions (Minimal vs Target) 为什么不能将较早的xamarin表单版本作为nuget添加到Xamarin表单项目/ android程序包中? - Why can't I add a earlier xamarin forms version as a nuget into my Xamarin forms project/android package?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM