How to include MEF in Unity 2020 LTS ? (resolved)
I tried to include MEF library in Unity 2020 LTS
My project settings
Scripting Backend: Mono
Api Compatibility Level: .Net Standard 2.0
Here are my steps to try and include an external library:
nupkg has been loaded from nuget.org
Then i got the system.componentmodel.composition.5.0.0.nupkg
And when i unpacked .nupkg file i got netstandard2.0/System.ComponentModel.Composition.dll
Then i added System.ComponentModel.Composition.dll to Assets folder
Then i got this error messages in console:
Error: Could not load signature of System.ComponentModel.Composition.Hosting.CompositionContainer:ReleaseExports due to: Could not resolve type with token 0100003c (from typeref, class/assembly System.Lazy`2, netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) assembly:netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 type:System.Lazy`2 member:(null) signature:
Search for information
Some people say to create mcs.rsp file, which is now called scs.rsp as far as I understand.
And inside the file you have to add this line, it is only valid for mcs.rsp :
-r:System.ComponentModel.Composition
And for the file scs.rsp it should be correct:
-r:System.ComponentModel.Composition.dll
But I found Unity3d Manual page Referencing additional class library assemblies
And the following was written inside:
If your Project uses the .NET Standard
API Compatibility Level, you don’t need to take any additional steps to
use part of the .NET class library API.
Does this mean that I do not need to perform any additional steps in order for the library to start working?
It would be great if someone could help with this issue.
I have already tried the following points, but nothing works:
different versions of Unity (2018 LTS, 2019 LTS)
different versions of Api Compatibility Level (.Net 4.0)
creating scs.rsp file
creating mcs.rsp file
Answer by Akeyn · Apr 06, 2021 at 11:29 AM
I was able to make the library work.
I was looking for a solution for a long time, came across the fact that this library is contained in .NET 4.x and I had to figure out how to import library it better, and I found a very simple solution it is take the library from the Unity folder and drop it into the Assets folder
Steps to import .dll
I took the System.ComponentModel.Composition.dll library along the following path C:\Program Files\Unity\Hub\Editor\2020.3.2f1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit
Then I changed the Api Compatibility Level from .NET Standard 2.0 to .NET 4.x
Voila everything works.
If it was helpful, please like it ;)
OMG, you are such a life saver! Why .Net Standard doesn't work, but I did notice even though the api is pointed to 2.0, the Unity project is still 4.7.1. I did did my library in 4.7.1, which was a pain since VS 2019 doesn't allow you too. I did all your recommendations and Finally I have my DryIoc using DI on all my game objects. Kudos!
Your answer

Follow this Question
Related Questions
Visual Studio Move Drive 1 Answer
MonoDevelop Error While Trying to Load the Project "expected ';' (3B) but found ' ' (20)" 2 Answers
How to enable 'unsafe' code option when debugging using Monodevelop 1 Answer
Cant use monodevelop anymore 1 Answer
Cannot get intellisense to work in monodevelop for Unity (C# on windows). 1 Answer