Search Unity

The problem when I using asmdef and using the UnityEditor.iOS.Xcode

Discussion in 'Editor & General Support' started by watsonsong, Mar 31, 2018.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I am using the UnityEditor.iOS.Xcode correct when there is no asmdef file. When I add a asmdef file and I met a problem. The namespace of UnityEditor.iOS can not be found.
    How can I add it to the asmdef? I don't know where to lookup the correct name of UnityEditor.iOS in references.
     
  2. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I add some test, the editor will not report any error, but the visual studio can not attach because the visual studio report error.
     
  3. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I compare the different between my own asmdef project and the Assembly-CSharp-Editor.
    I find the Assembly-CSharp-Editor has reference to the UnityEditor.iOS.Extensions.Common and UnityEditor.iOS.Extensions.Xcode.
    But my own asmdef has only reference to UnityEditor.iOS.Extensions.

    I add the missing reference to my asmdef reference, but it seems not work:
    Code (JavaScript):
    1. {
    2.     "name": "MyDLL.Editor",
    3.     "references": [
    4.         "UnityEditor.iOS.Extensions.Common",
    5.         "UnityEditor.iOS.Extensions.Xcode",
    6.         "MyDLL"
    7.     ],
    8.     "optionalUnityReferences": [],
    9.     "includePlatforms": [
    10.         "Editor"
    11.     ],
    12.     "excludePlatforms": [],
    13.     "allowUnsafeCode": false
    14. }
    15.  
     
    Last edited: Mar 31, 2018
  4. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I build the DLL and the editor load the DLL correctly.
    But my visual studio can not attach to debug because it always report can not find UnityEditor.iOS.Xcode
    It seems the vs project generate is not correct when using asmdef
     
  5. piojox11

    piojox11

    Joined:
    Jul 16, 2015
    Posts:
    13
    Did you get this figured out? I'm experiencing this problem, whether or not I use .asmdef files.
     
  6. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Is there anyone know how to resolve this, the error in visual studio is really annoying~
     
  7. piojox11

    piojox11

    Joined:
    Jul 16, 2015
    Posts:
    13
    @watsonsong I think I figured it out. Let me know if this helps--reinstall Unity. Specifically install the Visual Studio Community part, even if you're not using Visual Studio. That seems to have fixed it for me.

    Something is broken in your computer's config (almost certainly broken by Unity's installer). I spoke with someone on the Unity QA team, and they can't reproduce even with a test project. So the problem is in the system configuration/setup, not the project.
     
  8. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I check the .csproject file and it has no reference to UnityEditor.iOS.Extensions.Common and UnityEditor.iOS.Extensions.XCode.
    I am using the .Net 4.x and net standard 2.0, is it the environment error?
     
  9. piojox11

    piojox11

    Joined:
    Jul 16, 2015
    Posts:
    13
    If your error is the same as mine, none of that matters. There is nothing you can do in your project settings to fix the problem. Install Unity and Visual Studio Community using the Unity 2017 installer. (You can still use MonoDevelop.) If that doesn't work, then it will be time to brainstorm other solutions.

    You could write some code to automatically add references to those two DLLs to your csproj files, but it's a lousy workaround. If you do that, you'll constantly need to reload the project, and because Unity frequently regenerates the project files, you'll also sometimes end up without the references anyway.
     
    Last edited: Apr 19, 2018
  10. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    @piojox11 I change a computer and reinstall the visual studio 2017, the result is the same:
    Code (CSharp):
    1. 1>------ 已启动生成: 项目: NirvanaEditor, 配置: Debug Any CPU ------
    2. 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets(84,5): warning MSB3052: 编译器的参数无效,“/define:0”将被忽略。
    3. 1>F:\Repositories\Nirvana\Assets\Nirvana\Editor\Build\ProductNameI18N.cs(14,27,14,32): error CS0234: 命名空间“UnityEditor.iOS”中不存在类型或命名空间名“Xcode”(是否缺少程序集引用?)
    4. 1>F:\Repositories\Nirvana\Assets\Nirvana\Editor\Build\XCodePostProcess.cs(14,27,14,32): error CS0234: 命名空间“UnityEditor.iOS”中不存在类型或命名空间名“Xcode”(是否缺少程序集引用?)
    5. 2>------ 已启动生成: 项目: Assembly-CSharp-firstpass, 配置: Debug Any CPU ------
    6. 2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets(84,5): warning MSB3052: 编译器的参数无效,“/define:0”将被忽略。
    7. 2>CSC : error CS0006: 未能找到元数据文件“F:\Repositories\Nirvana\Temp\bin\Debug\NirvanaEditor.dll
    8. 3>------ 已启动生成: 项目: Assembly-CSharp, 配置: Debug Any CPU ------
    9. 3>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets(84,5): warning MSB3052: 编译器的参数无效,“/define:0”将被忽略。
    10. 3>CSC : error CS0006: 未能找到元数据文件“F:\Repositories\Nirvana\Temp\bin\Debug\Assembly-CSharp-firstpass.dll
    11. 3>CSC : error CS0006: 未能找到元数据文件“F:\Repositories\Nirvana\Temp\bin\Debug\NirvanaEditor.dll
    12. ========== 生成: 成功 0 个,失败 3 个,最新 2 个,跳过 0==========
     
    Last edited: May 2, 2018
  11. piojox11

    piojox11

    Joined:
    Jul 16, 2015
    Posts:
    13
    You meant you used the Unity installer to install VS, right? If so, I have no more ideas. Sorry.
     
  12. piojox11

    piojox11

    Joined:
    Jul 16, 2015
    Posts:
    13
    I just found this can't be fixed in Unity 2018, but it works in Unity 2017.
     
  13. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    @piojox11 have you resolve this problem?
    I still have the same error by using the Unity2018.2b10
     
  14. piojox11

    piojox11

    Joined:
    Jul 16, 2015
    Posts:
    13
    @watsonsong Sorry I can't help more. Since this discussion started, I encountered this problem again, but solved it the same way. The only things I've done (and one of them was the solution) were uninstalling and reinstalling Unity and Visual Studio, but only reinstalling VS using the Unity installer, not the official installer.
     
  15. JeremyROH

    JeremyROH

    Joined:
    Feb 26, 2018
    Posts:
    2
    @watsonsong, @piojox11
    Hi, I'm experiencing the same problem at the moment with 2018.2.8f1.
    I have no doubt that it is something to do with asmdef.

    1. If I remove asmdef, then it doesn't give the errors with missing UnityEditor.iOS.xxx.

    2. Unity Cloud Build has exactly the same problem. If it's such a system configuration problem particularly on my dev environment, then Unity Cloud Build is supposed to be working. However, Unity Cloud Build also failed to come out a build due to the same error: missing UnityEditor.iOS.xxx reference.

    So frustrated.
    I dare not uninstall/reinstall applications unless there's a confirm and 100% guarantee to fix the problem by doing that.
    At the moment, I gotta forget about using asmdef.
     
  16. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    @JeremyROH, I am tring the 2018.3b9 and this problem is the same. If I using the asmdef, this error happen. No matter whether how many time I reinstall unity, reinstall visual studio 2017, reinstall windows 10, even change another windows computer this error is the same.

    Is there any more body met this problem, I hope the unity can fix it.
     
  17. Deleted User

    Deleted User

    Guest

    This issue is blocking iOS unity cloud build with xcode post processing for us.
    I cannot find a way to reference UnityEditor.iOS.Extensions.Xcode.dll in asmdef.
    In my csproj, this is easy. But as Unity generates the csproj from the .asmdef, I don't see a feasible way to do this.
     
  18. andrewow

    andrewow

    Joined:
    Dec 2, 2013
    Posts:
    13
    If anyone is looking at this, you have to put the script in an Editor folder
     
  19. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    @andrewow, I am put my script in the Editor folder. What cause this is I am using the asmdef file.
     
  20. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
  21. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I place my editor asmdef file and all source code inside the Editor folder. And enable the Auto Reference, the Inlucde Platforms I select only Editor.
     
  22. Macoron

    Macoron

    Joined:
    Mar 11, 2017
    Posts:
    33
    I also reproduced this bug recently, I wrote a simple script that fixes .csproj and write path to .dll
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System;
    4. using System.IO;
    5. using System.Text;
    6.  
    7. public class PostProcessVisualStudioCSProject : AssetPostprocessor
    8. {
    9.     private static string pathToDll = "/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.Xcode.dll";
    10.  
    11.     private static string template = "<Reference Include=\"UnityEditor.iOS.Xcode\">" +
    12.         "<HintPath>{0}</HintPath></Reference>";
    13.  
    14.     static public void OnGeneratedCSProjectFiles()
    15.     {
    16.         // Open the solution file
    17.         string projectDirectory = System.IO.Directory.GetParent(Application.dataPath).FullName; ;
    18.         string projectName = Path.GetFileName(projectDirectory);
    19.         string slnFile = Path.Combine(projectDirectory, "com.unity.arkitplugin.editor.csproj");
    20.  
    21.         try
    22.         {
    23.             var file = File.ReadAllText(slnFile);
    24.  
    25.             if (file.Contains("UnityEditor.iOS.Extensions.Xcode"))
    26.                 return;
    27.  
    28.             var index = file.LastIndexOf("<Reference Include=\"UnityEditor.iOS.Extensions\">");
    29.  
    30.             var editorPath = Path.GetDirectoryName(UnityEditor.EditorApplication.applicationPath);
    31.             var finalPath = editorPath + pathToDll;
    32.             var final = string.Format(template, finalPath);
    33.  
    34.             var newFile = file.Insert(index, final);
    35.  
    36.             File.WriteAllText(slnFile, newFile);
    37.  
    38.         }
    39.         catch (Exception e)
    40.         {
    41.             Console.WriteLine("The file could not be read:");
    42.             Console.WriteLine(e.Message);
    43.         }
    44.     }
    45. }
    You will need to replace "com.unity.arkitplugin.editor.csproj" to your .asmdef package name.
    After that delete all .cs files in your project and click "Assets/Open C# Project".
    That's it! You can debug with Visual Studio again. Unity, please, fix it!