Search Unity

[SOLVED] How to install Infer.NET to Unity 2018.3

Discussion in 'Formats & External Tools' started by Matti-Jokipii, May 7, 2019.

  1. Matti-Jokipii

    Matti-Jokipii

    Joined:
    Apr 24, 2015
    Posts:
    16
    I have a fresh Unity project and following the instructions in Using .NET 4.x in Unity, i've downloaded Microsoft.ML.Probabilistic.Compiler NuGet package from the gallery and copied the DLL to Assets/Plugins. After this Unity outputs an error message

    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?

    I downloaded and copied the missing DLL and every following missing DLL dependency
    • Microsoft.ML.Probabilistic.dll
    • System.CodeDom.dll
    • Microsoft.CodeAnalysis.CSharp.dll
    • Microsoft.CodeAnalysis.dll
    • System.Collections.Immutable.dll
    • System.Reflection.Metadata.dll
    Unity showed no more errors after adding the System.Reflection.Metadata.dll.

    When i add
    Code (CSharp):
    1. using Microsoft.ML.Probabilistic;
    2. using Microsoft.ML.Probabilistic.Compiler;
    3.  
    to a script, the project builds fine in both Unity and Visual Studio Community, but when i attempt to use the libraries
    Code (CSharp):
    1. using UnityEngine;
    2. using Microsoft.ML.Probabilistic;
    3. using Microsoft.ML.Probabilistic.Compiler;
    4.  
    5. public class Main : MonoBehaviour {
    6.     void Start () {
    7.         Variable<bool> firstCoin = Variable.Bernoulli (0.5);
    8.     }
    9. }
    both Unity and Visual Studio fail with

    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?)

    and

    Assets/Scripts/Main.cs(7,30): error CS0103: The name 'Variable' does not exist in the current context​

    Adding
    -r:Microsoft.ML.Probabilistic.Compiler.dll
    to Assets/mcs.rsp file generates an error

    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

    The project configuration is
    • Unity 2018.3.10f1
    • Visual Studio for Mac Community
    • Build Settings/Platform: iOS
    • Player Settings/Scripting Runtime Version: .NET 4.x Equivalent
    it makes no difference whether i set
    • Player Settings/Api Compatibility Level: .NET 4.x
    or
    • Player Settings/Api Compatibility Level: .NET Standard 2.0
    Other settings are left to their defaults.

    I haven't added the DLLs to the vs-project in Visual Studio as the guide says

    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.

    This is a cross post with my Stack Overflow question that i've received no answers
    https://stackoverflow.com/questions/56019411/how-to-install-infer-net-to-unity-2018-3

    I would love to use this library and would appreciate any help you can offer.
     
  2. Matti-Jokipii

    Matti-Jokipii

    Joined:
    Apr 24, 2015
    Posts:
    16
    Hmm... no replies. Help me out if you know a better subforum for this kind of question. Not exactly sure this is a question for External Tools.
     
  3. Matti-Jokipii

    Matti-Jokipii

    Joined:
    Apr 24, 2015
    Posts:
    16
    For anyone interested, the above installation actually works, i was just missing the fact that the Variable<T> is in the Microsoft.ML.Probabilistic.Models namespace. FYI: The library doesn't support AOT so it won't work on iOS.