简体   繁体   English

使用Visual Studio中内置的外部DLL统一构建UWP应用,会在Task类上生成错误

[英]Building an UWP app from unity, using external dll built in visual studio, generates an error on the Task class

I made an UWP application in Unity for Hololens and I added in the Assets a class using Tasks (System.Threading.Tasks). 我在Unity for Hololens中创建了UWP应用程序,并在资产中使用Tasks(System.Threading.Tasks)添加了一个类。 The code of the class is surrounded by the compilation directive as follow: 该类的代码由以下编译指令包围:

#if WINDOWS_UWP #if WINDOWS_UWP
.... Code Here ....在这里编码
#endif #万一

since it needs to work only on the device. 因为它只需要在设备上工作即可。

I successfully deployed the application on the Hololens. 我已在Hololens上成功部署了该应用程序。

But when I try to move the class in an external dll, generated compiling a Class Library (Universal Windows) project in Visual studio, and I reference it in Unity, when compiling I get the following error: 但是,当我尝试将类移动到外部dll中时,在Visual Studio中生成了一个编译类库(通用Windows)项目,并在Unity中引用了它,编译时出现以下错误:

... type 'Task<>' claims it is defined in 'System.Runtime', but it could not be found. ...类型“ Task <>”声称它是在“ System.Runtime”中定义的,但是找不到。

It seems that it is not using System.Threading.Tasks, but it tries to use a Task class defined in System.Runtime. 似乎它没有使用System.Threading.Tasks,但是它尝试使用System.Runtime中定义的Task类。

Why this happens only if the class is in an external dll and I works when the class is directly in the assets folder? 为什么仅当该类位于外部dll中并且该类直接位于Assets文件夹中时才起作用,为什么会发生这种情况?

Since I need to have the code in the external dll how can I fix it? 由于我需要外部dll中的代码,该如何解决?

The problem was in the minimun SDK version of the UWP library. 问题出在UWP库的minimun SDK版本中。

By default Unity uses Windows 10 (10.0; Build 10240) when building UWP applications, while the minimum version of the UWP Library was Windows 10 Creators Update (10.0; Build 15063) . 默认情况下,Unity在构建UWP应用程序时使用Windows 10(10.0; Build 10240) ,而UWP库的最低版本是Windows 10 Creators Update(10.0; Build 15063)

Setting up the SDK minimum version of the UWP Class library in visual studio to Windows 10 (10.0; Build 10240) , and reimporting the dll in Unity, solved my problem. 在Visual Studio中将UWP类库的SDK最低版本设置为Windows 10(10.0; Build 10240) ,然后在Unity中重新导入dll,解决了我的问题。

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

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