Xamarin.Mac 4.5与BCL异步发布编译无法解析System.Threading.Tasks

时间:2014-03-12 19:10:54

标签: c# xamarin portable-class-library base-class-library

我一直在Xamarin Studio中使用带有可移植库和Xamarin.Mac项目的.NET 4.5。当Xamarin.Mac项目设置为.NET 4.5并通过nuget添加Microsoft Async时,Debug中的编译将成功,但Release / AppStore将失败

  

错误MM2002:无法解析程序集:' System.Threading.Tasks,

在这种情况下,没有必要从BCL添加dll(System.Threading.Tasks和System.Runtime),因为它们已经在.NET 4.5中。如果你切换到.NET 4.0它会工作,但我已经有很多代码已经在.NET 4.5中由于其他依赖性而无法逆转。

不知何故,BCL没有将Xamarin.Mac .NET 4.5项目识别为.NET 4.5并且仍然需要dll。

要复制:

  1. 创建一个新的Xamarin.Mac项目
  2. 将其设置为.NET 4.5
  3. 使用nuget获取Microsoft Async(请注意,它不会引入System.Threading.Tasks或System.Runtime)
  4. 切换到发布
  5. 编译
  6. 如果使用.NET 4.0或.NET 4.5,BCL如何知道?也许我可以在csproj中声明一些东西,使它能够识别System.Threading.Tasks(和System.Runtime)已经包含在内。或者可能是一些环境变量?还是...?

    注意。可以从net40 nuget文件夹中引用System.Threading.Tasks和System.Runtime。在测试项目中,这实际上是有效的 - 虽然它抱怨"预定义类型System.Runtime.CompilerServices.AsyncStateMachineAttribute' is defined multiple times. Using definition from mscorlib.dll'"但是,在我的情况下,我有一个使用EventArgs的可移植库,并且构建失败,错误CS1684:引用类型System.EventArgs' claims it is defined assembly System.Runtime - 当然它不是。

1 个答案:

答案 0 :(得分:1)

我不确定Xamarin.Mac如何支持PCL。您可以尝试使用绑定重定向添加app.config,类似于此处所述:http://motzcod.es/post/78863496592/portable-class-libraries-httpclient-so-happy

否则,我建议向Xamarin提交错误。