Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Building a DLL targeting .Net 3.5 or earlier with Visual Studio for Mac

Discussion in 'Scripting' started by Pelican_7, Apr 6, 2018.

  1. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Hi all,

    I'm currently trying to build a simple DLL for use in Unity with Visual Studio for Mac. However, I am unable to successfully build the DLL targeting a version of .NET prior to 3.5, as Unity requires.

    My DLL consists of one source file containing:
    Code (CSharp):
    1. using System;
    2.  
    3. namespace SimpleDLLTest
    4. {
    5.     public class Class1
    6.     {
    7.         public void HelloWorld()
    8.         {
    9.             Console.WriteLine("Hello world.");
    10.         }
    11.     }
    12. }
    I can then build this DLL successfully in Visual Studio for Mac. However, when adding the DLL to Unity, I see the following error in the inspector:
    Therefore, I am attempting to build my DLL with a target of .NET 3.5 or earlier. I have downloaded Mono version 3.2.7 from https://download.mono-project.com/archive/. In Visual Studio for Mac, I can select this runtime for my DLL in Project --> Active Runtime --> Mono 3.2.7. However, now when I build I receive an error in the build log with no additional information:
    Would anyone be so gracious as to give me a pointer on where I might be going wrong?! Or how I might get more details on the error being generated by Visual Studio?

    Setup
    • Unity 2017.3.0f3
    • Visual Studio for Mac 7.4.2

    Thanks!
    Andy
     
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    AFAIK Mono version does not directly correspond to Unity's Mono version.
    Also why are you limiting yourself to .net 3.5? Unity has been capable of .net 4.5 (experimental equivalentTM) for a while now. If you MUST stay on .net 3.5, try building a library for .net 2.0.
     
  3. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Thanks for the response @FMark92.
    I'm planning to release on the Asset Store and so don't want to force users to use .NET 4.5 in Unity, when I don't use any features requiring .NET 4.5.
    I get the exact same result repeating the above process with Mono 2.0, I'm afraid.

    img.png
     
  4. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Have you tried using Unity's Mono instead of the current Mono release to build the library?
     
  5. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Same result I'm afraid. I tried building with Unity's Mono (v2.6.5) located at Unity.app/Contents/Mono but still the same error with no information. :confused:
     
  6. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Looking in the IDE.log file, found by selecting Help/Open Log Directory in Visual Studio for Mac, I can see the build error is the following:
    Which lead me to this post on Stack Overflow, in which the answer states:
    So earlier versions of Mono don't include msbuild, which Visual Studio is attempting to use when building for older Active Runtimes. So, what is the correct way of building DLLs with Visual Studio for Mac with older versions of Mono (< .NET 3.5), for use in Unity?
     
    davidwmd likes this.
  7. codespark-james

    codespark-james

    Joined:
    Jun 19, 2018
    Posts:
    1
    I have this exact same question. I'm trying to build a dll for .NET 3.5 and followed most of the steps outlined above and have had no joy.
     
  8. gStormDesign

    gStormDesign

    Joined:
    May 27, 2013
    Posts:
    30
    Ditto. And bump. Found all the above, and no solution yet. Anyone else find clues? (assembly reference options or the like?)