Search Unity

how to compile a .net framework project with IL2CPP

Discussion in 'Windows' started by Max-_-Well, Apr 7, 2020.

  1. Max-_-Well

    Max-_-Well

    Joined:
    Apr 2, 2020
    Posts:
    13
    When i try to compile a Unity script manually, i had this problem.
    After compiling the Unity project with VS2019, i try to use UnityLinker.exe to stripe the dlls.

    My command is :

    Code (CSharp):
    1. UnityLinker -out=D:\MyDoc\IL2CPP\Temp\bin\build -d=D:\MyDoc\IL2CPP\Temp\bin\Debug -dotnetruntime=il2cpp --use-editor-options --dotnetprofile=unityaot --include-unity-root-assembly=D:\MyDoc\IL2CPP\Temp\bin\Debug\Assembly-CSharp.dll --include-directory=D:\MyDoc\IL2CPP\Temp\bin\Debug --rule-set=Conservative
    Then this error appeared:

    Code (CSharp):
    1. UnityLinker -out=D:\MyDoc\IL2CPP\Temp\bin\build -d=D:\MyDoc\IL2CPP\Temp\bin\Debug -dotnetruntime=il2cpp --use-editor-options --dotnetprofile=unityaot --include-unity-root-assembly=D:\MyDoc\IL2CPP\Temp\bin\Debug\Assembly-CSharp.dll --include-directory=D:\MyDoc\IL2CPP\Temp\bin\Debug --rule-set=Conservative
    2. Fatal error in Unity CIL Linker
    3. Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
    4.    in Unity.Linker.EngineStripping.EngineModule.<ResolvedReferences>d__13.MoveNext()
    5.    in Unity.Linker.Steps.Resolution.ResolveForEngineModuleStrippingDisabledStep.MarkModuleReferences(EngineModule module, HashSet`1 processed)
    6.    in Unity.Linker.Steps.Resolution.ResolveForEngineModuleStrippingDisabledStep.MarkModule(EngineModule module, HashSet`1 processed)
    7.    in Unity.Linker.Steps.Resolution.ResolveForEngineModuleStrippingDisabledStep.Process(LinkContext context)
    8.    in Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
    9.    in Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
    10.    in Mono.Linker.Pipeline.Process(LinkContext context)
    11.    in Unity.Linker.UnityDriver.Run()
    12.    in Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling()
    13.    in Unity.Linker.UnityDriver.RunDriver()
     
  2. Max-_-Well

    Max-_-Well

    Joined:
    Apr 2, 2020
    Posts:
    13
    I know there is a reason that debug directory contains too many useless dlls.i can run this command in directory:..\IL2CPP_BackUpThisFolder_ButDontShipItWithYourGame\Managed
    But i don't know how to deal with it.
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    What are you trying to achieve? I don't quite understand...
     
  4. Max-_-Well

    Max-_-Well

    Joined:
    Apr 2, 2020
    Posts:
    13
    I created a new C # class library project in VS. I want to convert the DLL built by this project convert to C ++ code with IL2CPP.
    I find that there is two steps to convert a dll to c++ in Unity: dll -> UnityLink.exe and IL2CPP.exe -> C++.
    But I got stuck in the first step.

    Is this correct? Or is there any other way to solve this problem? TKX.
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Why are you trying to convert a DLL on its own? Are you not using IL2CPP in your Unity project?
     
  6. Max-_-Well

    Max-_-Well

    Joined:
    Apr 2, 2020
    Posts:
    13
    I just want to know if IL2CPP can be used outside of Unity. TKX.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    We don't support use of IL2CPP outside of a Unity project.
     
  8. Max-_-Well

    Max-_-Well

    Joined:
    Apr 2, 2020
    Posts:
    13
    THX!
    But i still have a problem:
    After successfully building a unity project with il2cpp, i found a fold called ...\IL2CPP_BackUpThisFolder_ButDontShipItWithYourGame\Managed.
    I can convert the dll in this fold with il2cpp.exe in CMD.
    But i can't convert the dll in the fold ...\Temp\bin\Debug which is the same Unity project built with VS2019.

    Code (CSharp):
    1. D:\Program Files\Unity\2019.3.4f1\Editor\Data\il2cpp\build\deploy\net471>il2cpp --convert-to-cpp --directory=D:\MyDoc\IL2CPP\Temp\bin\Debug --generatedcppdir=D:\MyDoc\IL2CPP\Temp\bin\build
    2. IL2CPP error for method 'System.Void System.Security.Authentication.ExtendedProtection.Configuration.ExtendedProtectionPolicyElement::.ctor()' in assembly 'D:\MyDoc\IL2CPP\Temp\bin\Debug\System.dll'
    3. Additional information: Failed to resolve assembly: 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    4. il2cpp.exe didn't catch exception: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    5.   in Unity.IL2CPP.Common.AssemblyResolver.ResolveInternal(AssemblyNameReference name)
    6.   in Unity.IL2CPP.Common.AssemblyResolver.Resolve(AssemblyNameReference name)
    7.   in Unity.IL2CPP.Common.WindowsRuntimeAwareMetadataResolver.Resolve(TypeReference type)
    8.   in Mono.Cecil.TypeReference.Resolve()
    9.   in Unity.IL2CPP.Extensions.GetBaseType(TypeReference typeReference)
    10.   in Unity.IL2CPP.GenericSharing.GenericSharingVisitor.AddStaticUsageRecursiveIfNeeded(TypeReference genericType)
    11.   in Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Process(Instruction instruction, MethodDefinition method)
    12.   in Unity.IL2CPP.GenericSharing.GenericSharingVisitor.ProcessType(TypeDefinition type, IGenericSharingAnalysisService sharingAnalysisService)
    13.   in Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Collect(AssemblyDefinition assembly, IGenericSharingAnalysisService genericSharingAnalysisService)
    14.   in Unity.IL2CPP.AssemblyConverter.Apply()
    15.   in Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    16.   in il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
    17.   in il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
    18.   in il2cpp.Program.Main(String[] args)
    19.  
    20. ...:  Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    21.   in Unity.IL2CPP.Common.AssemblyResolver.ResolveInternal(AssemblyNameReference name)
    22.   in Unity.IL2CPP.Common.AssemblyResolver.Resolve(AssemblyNameReference name)
    23.   in Unity.IL2CPP.Common.WindowsRuntimeAwareMetadataResolver.Resolve(TypeReference type)
    24.   in Mono.Cecil.TypeReference.Resolve()
    25.   in Unity.IL2CPP.Extensions.GetBaseType(TypeReference typeReference)
    26.   in Unity.IL2CPP.GenericSharing.GenericSharingVisitor.AddStaticUsageRecursiveIfNeeded(TypeReference genericType)
    27.   in Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Process(Instruction instruction, MethodDefinition method)
    28.   in Unity.IL2CPP.GenericSharing.GenericSharingVisitor.ProcessType(TypeDefinition type, IGenericSharingAnalysisService sharingAnalysisService)
    29.   in Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Collect(AssemblyDefinition assembly, IGenericSharingAnalysisService genericSharingAnalysisService)
    30.   in Unity.IL2CPP.AssemblyConverter.Apply()
    31.   in Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    32.   in il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
    33.   in il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
    34.   in il2cpp.Program.Main(String[] args)
    35.  
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    I'm unsure why this is a problem. If the Unity player build works correctly, then all of the code should be compiled into that player build. There should be no need to convert another assembly with IL2CPP. The assemblies in the IL2CPP_BackUpThisFolder_ButDontShipItWithYourGame\Managed folder are a copy of the assemblies that IL2CPP converted. They are useful for debugging issues with the game later, but there is no need to attempt to convert them with IL2CPP again.
     
  10. Max-_-Well

    Max-_-Well

    Joined:
    Apr 2, 2020
    Posts:
    13
    I understand, thank you, you are very enthusiastic.
     
    waynemunro likes this.