Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

SyntaxTree missing reference

Discussion in 'Windows' started by Lucarma79, Feb 6, 2016.

  1. Lucarma79

    Lucarma79

    Joined:
    Feb 14, 2015
    Posts:
    5
    With the previous version of Unity (earlier than 5.3.2f1) I solved the losing of the sistem data dll in the projects using the following answer:

    http://answers.unity3d.com/questions/999080/how-to-fix-losing-systemdatadll-in-project.html

    But after the unity update, in Visual Studio 2015, I can't find the way to add the following rows without the 'wrong type or namespace' error (line 1) or the 'ProjectFilesGenerator does not exist in the current context' error (line 8).

    Code (CSharp):
    1.  
    2. using SyntaxTree.VisualStudio.Unity.Bridge
    3.  
    4. ...
    5.  
    6. static ProjectFileHook()
    7.     {
    8.         ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
    9.         {
    10.             var document = XDocument.Parse(content);
    11.  
    12.             RemoveFileFromProject(document, @"Assets\plugins\System.Data.dll");
    13.             RemoveHintPathFromReference(document, "System.Data");
    14.             var str = new Utf8StringWriter();
    15.             document.Save(str);
    16.  
    17.             return str.ToString();
    18.         };
    19.     }
    Thank you
    Luca
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,956
    What is
    Code (csharp):
    1.  
    2. static ProjectFileHook
    3.  
    if it's a function, where its return type? Also is it inside a class?
     
  3. Lucarma79

    Lucarma79

    Joined:
    Feb 14, 2015
    Posts:
    5
    Sorry for the mistake, I add all the file I used for solve the losing of the dll.

    Code (CSharp):
    1. #if UNITY_STANDALONE_WIN
    2.  
    3. using System;
    4. using System.IO;
    5. using System.Linq;
    6. using System.Text;
    7. using System.Xml.Linq;
    8. using UnityEditor;
    9. using UnityEngine;
    10. using SyntaxTree.VisualStudio.Unity.Bridge;
    11.  
    12. [InitializeOnLoad]
    13. public class ProjectFileHook
    14. {
    15.     // necessary for XLinq to save the xml project file in utf8
    16.     class Utf8StringWriter : StringWriter
    17.     {
    18.         public override Encoding Encoding
    19.         {
    20.             get { return Encoding.UTF8; }
    21.         }
    22.     }
    23.  
    24.     static void ProcessNodesWithIncludeAttribute(XDocument document, string localName, string includeValue, Action<XElement> action)
    25.     {
    26.         var nodes = document
    27.             .Descendants()
    28.             .Where(p => p.Name.LocalName == localName);
    29.  
    30.         foreach (var node in nodes)
    31.         {
    32.             var xa = node.Attribute("Include");
    33.             if (xa != null && !string.IsNullOrEmpty(xa.Value) && string.Equals(xa.Value, includeValue))
    34.             {
    35.                 action(node);
    36.             }
    37.         }      
    38.     }
    39.  
    40.     // Remove System.Data from project (not from file system so Unity can compile properly)
    41.     static void RemoveFileFromProject(XDocument document, string fileName)
    42.     {
    43.         ProcessNodesWithIncludeAttribute(document, "None", fileName, element => element.Remove());      
    44.     }
    45.  
    46.     // Adjust references, by using the default framework assembly instead of local file (remove the HintPath)
    47.     static void RemoveHintPathFromReference(XDocument document, string assemblyName)
    48.     {
    49.         ProcessNodesWithIncludeAttribute(document, "Reference", assemblyName, element => element.Nodes().Remove());      
    50.     }
    51.  
    52.     static ProjectFileHook()
    53.     {
    54.         ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
    55.         {
    56.             var document = XDocument.Parse(content);
    57.  
    58.             RemoveFileFromProject(document, @"Assets\plugins\System.Data.dll");
    59.             RemoveHintPathFromReference(document, "System.Data");
    60.             var str = new Utf8StringWriter();
    61.             document.Save(str);
    62.  
    63.             return str.ToString();
    64.         };
    65.     }
    66. }
    67.  
    68. #endif
    With this code I prevent the losing of the System.data.dll from the project in Visual Studio. My OS is Windows 10, and the version of Visual Studio is 2015(free version). The problem is related to the "missing namespace" that the newest version of Unity does not reconize
     
  4. Nokola

    Nokola

    Joined:
    Jul 25, 2015
    Posts:
    5
    I just had a similar issue after updating VS 2017 today.
    The fix:
    1. Navigate to your VS folder and find this subfolder e.g. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity
    2. Double-click Visual Studio 2017 Tools.unitypackage and import in Unity

    Hope that helps!
     
  5. CL_HG

    CL_HG

    Joined:
    Mar 5, 2014
    Posts:
    6
    This didn't fix it for me.. any other solutions?

    FIXED:
    Never mind.. The issue was that MonoDevelop for whatever reason, could not find the files in the Unity project. So using the Visual Studio unitypackage was fixing it, actually.
     
    Last edited: Oct 17, 2017
    someguywithamouse and Lohoris2 like this.
  6. someguywithamouse

    someguywithamouse

    Joined:
    Mar 25, 2018
    Posts:
    9
    Is that included in Visual Studio Code as well? I can't find it in my files. I don't have VS '15 or '17.