自定义 dll 集成到 HoloLens 项目中
Custom dll integration into a HoloLens project
我有一个带有源代码的自定义库,可以成功编译并生成 .dll 文件。
问题:考虑到以下错误,将此 dll 包含在 HoloLens 项目中的最佳方法是什么?
我的做法
独立库的project.json
文件如下:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
或者我也有机会将其添加为 NuGet 包,具体取决于:
- Microsoft.NETCore.UniversalWindowsPlatform (>= 5.2.2)
- Newtonsoft.Json (>= 9.0.1)
- Microsoft.EntityFrameworkCore.Tools(>=1.0.0-preview2-final)
- Microsoft.EntityFrameworkCore.Sqlite (>= 1.0.1)
然后我需要将这个库包含在另一个由 Unity for Hololens 制作的 VS2015 解决方案中。 Unity 自动构建的解决方案包含 3 个项目:1) Assembly-CSharp
包含一个 HoloToolkit 文件夹,2) Assembly-CSharp firstpass
和 3) Origami
我从 HoloToolkit for Unity 文件夹中获取了一个脚本并将其应用于 GameObject
。当一个事件被触发时——它成功发生了——我想调用这个自定义库提供的一些函数来从同一个脚本中处理它,比如 GazeManager.cs
。项目1)的project.json
如下
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
我尝试了两种方式:
- 在
GazeManager.cs
中我在代码中添加了using MyLibrary
并将其添加为ReferenceManager中的引用。该库得到正确识别,但随后只需声明一个变量,如 public MyLibrary objectInMyLibrary
就会从一个正确编译的程序切换到一个出现以下错误的程序:
The command ""C:\Users\Antonino\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Unity\Tools\AssemblyConverter.exe" -platform=uap -lock="C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\project.lock.json" -bits=32 -configuration=Debug -removeDebuggableAttribute=False -path="." -path="..\Players\UAP\x86\Debug" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\Assembly-CSharp.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\Assembly-CSharp-firstpass.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.UI.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.HoloLens.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.Networking.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.VR.dll"" exited with code 1.
[取消前面的步骤以再次编译 Origami] 我认为的第二种方法是通过在 project.json
文件
中插入行来添加它
"my.hololens.library": "version"
在这种情况下,我得到了以下错误
Payload contains two or more files with the same destination path 'System.Net.Sockets.dll'. Source files: C:\Users\Antonino.nuget\packages\runtime.win.System.Net.Sockets.1.0\runtimes\win\lib\netcore50\System.Net.Sockets.dllC:\Users\Antonino.nuget\packages\System.Net.Sockets.0.0\lib\netcore50\System.Net.Sockets.dll
Payload contains two or more files with the same destination path 'System.Diagnostics.Tools.dll'. Source files: C:\Users\Antonino.nuget\packages\runtime.any.System.Diagnostics.Tools.0.1\lib\netcore50\System.Diagnostics.Tools.dllC:\Users\Antonino.nuget\packages\System.Diagnostics.Tools.0.0\lib\netcore50\System.Diagnostics.Tools.dll
Payload contains two or more files with the same destination path 'System.Threading.Timer.dll'. Source files: C:\Users\Antonino.nuget\packages\runtime.any.System.Threading.Timer.0.1\lib\netcore50\System.Threading.Timer.dllC:\Users\Antonino.nuget\packages\System.Threading.Timer.0.0\lib\netcore50\System.Threading.Timer.dll
Version conflict detected for System.Collections. Origami (>= 1.0.0) -> Assembly-CSharp (>= 1.0.0) -> my.hololens.library (>= version) -> Microsoft.EntityFrameworkCore.Tools (>= 1.0.0-preview2-final) -> Microsoft.EntityFrameworkCore.Design (>= 1.0.0-preview2-final) -> Microsoft.EntityFrameworkCore.Design.Core (>= 1.0.0-preview2-final) -> Microsoft.AspNetCore.Hosting.Abstractions (>= 1.0.0) -> Microsoft.AspNetCore.Http.Abstractions (>= 1.0.0) -> System.Reflection.TypeExtensions (>= 4.1.0) -> System.Linq (>= 4.1.0) -> System.Collections (>= 4.0.11) Origami (>= 1.0.0) -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.0.0) -> Microsoft.NETCore.Runtime (>= 1.0.0) -> Microsoft.NETCore.Runtime.CoreCLR-arm (>= 1.0.0) -> System.Collections (= 4.0.10).
One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot).
One or more packages are incompatible with UAP,Version=v10.0 (win10-arm-aot).
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86-aot.
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64-aot.
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86-aot.
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-x64-aot).
Version conflict detected for System.Collections. Assembly-CSharp (>= 1.0.0) -> my.hololens.library (>= version) -> Microsoft.EntityFrameworkCore.Tools (>= 1.0.0-preview2-final) -> Microsoft.EntityFrameworkCore.Design (>= 1.0.0-preview2-final) -> Microsoft.EntityFrameworkCore.Design.Core (>= 1.0.0-preview2-final) -> Microsoft.AspNetCore.Hosting.Abstractions (>= 1.0.0) -> Microsoft.AspNetCore.Http.Abstractions (>= 1.0.0) -> System.Reflection.TypeExtensions (>= 4.1.0) -> System.Linq (>= 4.1.0) -> System.Collections (>= 4.0.11) Assembly-CSharp (>= 1.0.0) -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.0.0) -> Microsoft.NETCore.Runtime (>= 1.0.0) -> Microsoft.NETCore.Runtime.CoreCLR-arm (>= 1.0.0) -> System.Collections (= 4.0.10).
One or more packages are incompatible with UAP,Version=v10.0 (win10-x64-aot).
One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot).
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm-aot.
One or more packages are incompatible with UAP,Version=v10.0 (win10-arm-aot).
System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm-aot.
我不知道接下来会发生什么。有人说要制作一个可移植的库,我也尝试研究hereNETFramework、NETCore和NETStandard之间的关系,但似乎比预期的要复杂。
Unity 3d 不支持集成使用 .Net Core 框架的库。尝试将您的库创建为 .Net Framework 3.5 库并将其放入 Unity 项目的 Assets/Plugins 文件夹中。
您需要创建一个 UWP Library 项目并将您的代码移植到该项目并编译,删除错误
将编译后的 dll 放在 assets 文件夹中
如下所示更新 Inspector 属性
现在您可以在 #if !UNITY_EDITOR
块
下的统一脚本中访问此 dll
我有一个带有源代码的自定义库,可以成功编译并生成 .dll 文件。
问题:考虑到以下错误,将此 dll 包含在 HoloLens 项目中的最佳方法是什么?
我的做法
独立库的project.json
文件如下:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
或者我也有机会将其添加为 NuGet 包,具体取决于:
- Microsoft.NETCore.UniversalWindowsPlatform (>= 5.2.2)
- Newtonsoft.Json (>= 9.0.1)
- Microsoft.EntityFrameworkCore.Tools(>=1.0.0-preview2-final)
- Microsoft.EntityFrameworkCore.Sqlite (>= 1.0.1)
然后我需要将这个库包含在另一个由 Unity for Hololens 制作的 VS2015 解决方案中。 Unity 自动构建的解决方案包含 3 个项目:1) Assembly-CSharp
包含一个 HoloToolkit 文件夹,2) Assembly-CSharp firstpass
和 3) Origami
我从 HoloToolkit for Unity 文件夹中获取了一个脚本并将其应用于 GameObject
。当一个事件被触发时——它成功发生了——我想调用这个自定义库提供的一些函数来从同一个脚本中处理它,比如 GazeManager.cs
。项目1)的project.json
如下
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
我尝试了两种方式:
- 在
GazeManager.cs
中我在代码中添加了using MyLibrary
并将其添加为ReferenceManager中的引用。该库得到正确识别,但随后只需声明一个变量,如public MyLibrary objectInMyLibrary
就会从一个正确编译的程序切换到一个出现以下错误的程序:
The command ""C:\Users\Antonino\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Unity\Tools\AssemblyConverter.exe" -platform=uap -lock="C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\project.lock.json" -bits=32 -configuration=Debug -removeDebuggableAttribute=False -path="." -path="..\Players\UAP\x86\Debug" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\Assembly-CSharp.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\Assembly-CSharp-firstpass.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.UI.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.HoloLens.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.Networking.dll" "C:\Users\lakeb\Documents\UnityToVS2015Projects\HoloAcademy101 - Origami\Origami\App\Origami\UnityEngine.VR.dll"" exited with code 1.
[取消前面的步骤以再次编译 Origami] 我认为的第二种方法是通过在
中插入行来添加它project.json
文件"my.hololens.library": "version"
在这种情况下,我得到了以下错误
Payload contains two or more files with the same destination path 'System.Net.Sockets.dll'. Source files: C:\Users\Antonino.nuget\packages\runtime.win.System.Net.Sockets.1.0\runtimes\win\lib\netcore50\System.Net.Sockets.dllC:\Users\Antonino.nuget\packages\System.Net.Sockets.0.0\lib\netcore50\System.Net.Sockets.dll Payload contains two or more files with the same destination path 'System.Diagnostics.Tools.dll'. Source files: C:\Users\Antonino.nuget\packages\runtime.any.System.Diagnostics.Tools.0.1\lib\netcore50\System.Diagnostics.Tools.dllC:\Users\Antonino.nuget\packages\System.Diagnostics.Tools.0.0\lib\netcore50\System.Diagnostics.Tools.dll Payload contains two or more files with the same destination path 'System.Threading.Timer.dll'. Source files: C:\Users\Antonino.nuget\packages\runtime.any.System.Threading.Timer.0.1\lib\netcore50\System.Threading.Timer.dllC:\Users\Antonino.nuget\packages\System.Threading.Timer.0.0\lib\netcore50\System.Threading.Timer.dll Version conflict detected for System.Collections. Origami (>= 1.0.0) -> Assembly-CSharp (>= 1.0.0) -> my.hololens.library (>= version) -> Microsoft.EntityFrameworkCore.Tools (>= 1.0.0-preview2-final) -> Microsoft.EntityFrameworkCore.Design (>= 1.0.0-preview2-final) -> Microsoft.EntityFrameworkCore.Design.Core (>= 1.0.0-preview2-final) -> Microsoft.AspNetCore.Hosting.Abstractions (>= 1.0.0) -> Microsoft.AspNetCore.Http.Abstractions (>= 1.0.0) -> System.Reflection.TypeExtensions (>= 4.1.0) -> System.Linq (>= 4.1.0) -> System.Collections (>= 4.0.11) Origami (>= 1.0.0) -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.0.0) -> Microsoft.NETCore.Runtime (>= 1.0.0) -> Microsoft.NETCore.Runtime.CoreCLR-arm (>= 1.0.0) -> System.Collections (= 4.0.10). One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot). One or more packages are incompatible with UAP,Version=v10.0 (win10-arm-aot). System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86-aot. System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64-aot. System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x86-aot. System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-x64-aot. One or more packages are incompatible with UAP,Version=v10.0 (win10-x64-aot). Version conflict detected for System.Collections. Assembly-CSharp (>= 1.0.0) -> my.hololens.library (>= version) -> Microsoft.EntityFrameworkCore.Tools (>= 1.0.0-preview2-final) -> Microsoft.EntityFrameworkCore.Design (>= 1.0.0-preview2-final) -> Microsoft.EntityFrameworkCore.Design.Core (>= 1.0.0-preview2-final) -> Microsoft.AspNetCore.Hosting.Abstractions (>= 1.0.0) -> Microsoft.AspNetCore.Http.Abstractions (>= 1.0.0) -> System.Reflection.TypeExtensions (>= 4.1.0) -> System.Linq (>= 4.1.0) -> System.Collections (>= 4.0.11) Assembly-CSharp (>= 1.0.0) -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.0.0) -> Microsoft.NETCore.Runtime (>= 1.0.0) -> Microsoft.NETCore.Runtime.CoreCLR-arm (>= 1.0.0) -> System.Collections (= 4.0.10). One or more packages are incompatible with UAP,Version=v10.0 (win10-x64-aot). One or more packages are incompatible with UAP,Version=v10.0 (win10-x86-aot). System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm-aot. One or more packages are incompatible with UAP,Version=v10.0 (win10-arm-aot). System.Reflection.Emit.ILGeneration 4.0.1 provides a compile-time reference assembly for System.Reflection.Emit.ILGeneration on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm-aot.
我不知道接下来会发生什么。有人说要制作一个可移植的库,我也尝试研究hereNETFramework、NETCore和NETStandard之间的关系,但似乎比预期的要复杂。
Unity 3d 不支持集成使用 .Net Core 框架的库。尝试将您的库创建为 .Net Framework 3.5 库并将其放入 Unity 项目的 Assets/Plugins 文件夹中。
您需要创建一个 UWP Library 项目并将您的代码移植到该项目并编译,删除错误 将编译后的 dll 放在 assets 文件夹中 如下所示更新 Inspector 属性
现在您可以在 #if !UNITY_EDITOR
块