如何安装 Infer.NET 到 Unity 2018.3
How to install Infer.NET to Unity 2018.3
我有一个新的 Unity 项目并按照 Using .NET 4.x in Unity, i've downloaded Microsoft.ML.Probabilistic.Compiler NuGet package from the gallery 中的说明将 DLL 复制到 Assets/Plugins。之后Unity输出错误信息
Assembly 'Assets/Plugins/Microsoft.ML.Probabilistic.Compiler.dll' will
not be loaded due to errors: Unable to resolve reference
'Microsoft.ML.Probabilistic'. Is the assembly missing or incompatible
with the current platform?
我下载并复制了丢失的 DLL 和每个后续丢失的 DLL 依赖项
- Microsoft.ML.Probabilistic.dll
- System.CodeDom.dll
- Microsoft.CodeAnalysis.CSharp.dll
- Microsoft.CodeAnalysis.dll
- System.Collections.Immutable.dll
- System.Reflection.Metadata.dll
Unity 在添加 System.Reflection.Metadata.dll 后不再显示错误。
当我添加
using Microsoft.ML.Probabilistic;
using Microsoft.ML.Probabilistic.Compiler;
脚本,该项目在 Unity 和 Visual Studio 社区中构建良好,但是当我尝试使用库时,即 Microsoft.ML.Probabilistic.Compiler.Variable<T>
class
using UnityEngine;
using Microsoft.ML.Probabilistic;
using Microsoft.ML.Probabilistic.Compiler;
public class Main : MonoBehaviour {
void Start () {
Variable<bool> firstCoin = Variable.Bernoulli (0.5);
}
}
Unity 和 Visual Studio 都失败了
Assets/Scripts/Main.cs(7,3): error CS0246: The type or namespace name
'Variable<>' could not be found (are you missing a using directive or
an assembly reference?)
和
Assets/Scripts/Main.cs(7,30): error CS0103: The name 'Variable' does
not exist in the current context
将 -r:Microsoft.ML.Probabilistic.Compiler.dll
添加到 Assets/mcs.rsp 文件会产生错误
Microsoft (R) Visual C# Compiler version 2.9.1.65535 (9d34608e)
Copyright (C) Microsoft Corporation. All rights reserved.
error CS0006: Metadata file 'Microsoft.ML.Probabilistic.Compiler.dll'
could not be found
项目配置为
- 统一 2018.3.10f1
- Visual Studio Mac 社区
- 构建 Settings/Platform:iOS
- 播放器Settings/Scripting 运行时版本:.NET 4.x 等效
设置与否没有区别
- 播放器 Settings/Api 兼容级别:.NET
4.x
或
- 播放器Settings/Api兼容级别:.NET Standard 2.0
其他设置保留默认值。
我没有按照指南中的说明将 DLL 添加到 Visual Studio 中的 vs 项目
Visual Studio regenerates .csproj and .sln files for Unity projects
each time they're opened. As a result, you cannot add assembly
references directly in Visual Studio because they'll be lost upon
reopening the project. Instead, a special text file named mcs.rsp must
be used:
Create a new text file named mcs.rsp in your Unity project's root Assets directory.
On the first line in the empty text file, enter: -r:System.Net.Http.dll and then save the file. You can replace "System.Net.Http.dll" with any included assembly that might be missing a reference.
Restart the Unity editor.
Variable<bool>
不属于 Probabilistic
或 Probabilistic.Compiler
相反,您需要包括 using Microsoft.ML.Probabilistic.Models;
,其中 Variable<T>
是其中的一部分。
using UnityEngine;
using Microsoft.ML.Probabilistic.Models;//we need Probabilistic.Models
public class SomeScript : MonoBehaviour
{
void Start()
{
Variable<bool> firstCoin = Variable.Bernoulli(0.5);
}
}
使用 unity 2018.3 和 2019.1 进行了测试,均使用 .net 4.x 运行时,并且构建良好(尽管在 Windows 上应该没有什么区别)。
... and copied the DLL to Assets/Plugins. After this Unity outputs an error message
我个人不必为了让它工作而这样做。我使用 Install-Package Microsoft.ML.Probabilistic.Compiler -Version 0.3.1810.501
从 NuGet 直接将包下载到默认目录 (project/Packages/)。它也不需要我下载任何额外的 DLL。
我有一个新的 Unity 项目并按照 Using .NET 4.x in Unity, i've downloaded Microsoft.ML.Probabilistic.Compiler NuGet package from the gallery 中的说明将 DLL 复制到 Assets/Plugins。之后Unity输出错误信息
Assembly 'Assets/Plugins/Microsoft.ML.Probabilistic.Compiler.dll' will not be loaded due to errors: Unable to resolve reference 'Microsoft.ML.Probabilistic'. Is the assembly missing or incompatible with the current platform?
我下载并复制了丢失的 DLL 和每个后续丢失的 DLL 依赖项
- Microsoft.ML.Probabilistic.dll
- System.CodeDom.dll
- Microsoft.CodeAnalysis.CSharp.dll
- Microsoft.CodeAnalysis.dll
- System.Collections.Immutable.dll
- System.Reflection.Metadata.dll
Unity 在添加 System.Reflection.Metadata.dll 后不再显示错误。
当我添加
using Microsoft.ML.Probabilistic;
using Microsoft.ML.Probabilistic.Compiler;
脚本,该项目在 Unity 和 Visual Studio 社区中构建良好,但是当我尝试使用库时,即 Microsoft.ML.Probabilistic.Compiler.Variable<T>
class
using UnityEngine;
using Microsoft.ML.Probabilistic;
using Microsoft.ML.Probabilistic.Compiler;
public class Main : MonoBehaviour {
void Start () {
Variable<bool> firstCoin = Variable.Bernoulli (0.5);
}
}
Unity 和 Visual Studio 都失败了
Assets/Scripts/Main.cs(7,3): error CS0246: The type or namespace name 'Variable<>' could not be found (are you missing a using directive or an assembly reference?)
和
Assets/Scripts/Main.cs(7,30): error CS0103: The name 'Variable' does not exist in the current context
将 -r:Microsoft.ML.Probabilistic.Compiler.dll
添加到 Assets/mcs.rsp 文件会产生错误
Microsoft (R) Visual C# Compiler version 2.9.1.65535 (9d34608e) Copyright (C) Microsoft Corporation. All rights reserved.
error CS0006: Metadata file 'Microsoft.ML.Probabilistic.Compiler.dll' could not be found
项目配置为
- 统一 2018.3.10f1
- Visual Studio Mac 社区
- 构建 Settings/Platform:iOS
- 播放器Settings/Scripting 运行时版本:.NET 4.x 等效
设置与否没有区别
- 播放器 Settings/Api 兼容级别:.NET 4.x
或
- 播放器Settings/Api兼容级别:.NET Standard 2.0
其他设置保留默认值。
我没有按照指南中的说明将 DLL 添加到 Visual Studio 中的 vs 项目
Visual Studio regenerates .csproj and .sln files for Unity projects each time they're opened. As a result, you cannot add assembly references directly in Visual Studio because they'll be lost upon reopening the project. Instead, a special text file named mcs.rsp must be used:
Create a new text file named mcs.rsp in your Unity project's root Assets directory.
On the first line in the empty text file, enter: -r:System.Net.Http.dll and then save the file. You can replace "System.Net.Http.dll" with any included assembly that might be missing a reference.
Restart the Unity editor.
Variable<bool>
不属于 Probabilistic
或 Probabilistic.Compiler
相反,您需要包括 using Microsoft.ML.Probabilistic.Models;
,其中 Variable<T>
是其中的一部分。
using UnityEngine;
using Microsoft.ML.Probabilistic.Models;//we need Probabilistic.Models
public class SomeScript : MonoBehaviour
{
void Start()
{
Variable<bool> firstCoin = Variable.Bernoulli(0.5);
}
}
使用 unity 2018.3 和 2019.1 进行了测试,均使用 .net 4.x 运行时,并且构建良好(尽管在 Windows 上应该没有什么区别)。
... and copied the DLL to Assets/Plugins. After this Unity outputs an error message
我个人不必为了让它工作而这样做。我使用 Install-Package Microsoft.ML.Probabilistic.Compiler -Version 0.3.1810.501
从 NuGet 直接将包下载到默认目录 (project/Packages/)。它也不需要我下载任何额外的 DLL。