[英]In a DNX project, how can I target for Xamarin Android?
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
更改它?
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项目瞄准
net45
, dnx45
和dotnet
(赞成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, nuget will need to also be updated to take in charge the new monikers that are being thought about to simplify the references.
为了支持这种情况,还需要更新nuget以负责正在考虑简化参考的新标记。
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兼容。
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.