Dan
Dan

Reputation: 7744

The namespace name 'SyntaxTree' could not be found

I have am developing in Unity 2019.2.3f1. I am trying to write a script that can Customize project files created by VSTU. In case the link ever gets removed, I have included a script very similar to the one from the link.

#if ENABLE_VSTU
using System.IO;
using System.Text;
using System.Xml.Linq;
using UnityEditor;
using SyntaxTree.VisualStudio.Unity.Bridge;

[InitializeOnLoad]
public class ProjectFileHook
{
    private class Utf8StringWriter : StringWriter
    {
        public override Encoding Encoding => Encoding.UTF8;
    }

    static ProjectFileHook()
    {
        ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
        {
            // parse the document and make some changes
            XDocument document = XDocument.Parse(content);
            document.Root?.Add(new XComment("FIX ME"));

            // save the changes using the Utf8StringWriter
            Utf8StringWriter str = new Utf8StringWriter();
            document.Save(str);

            return str.ToString();
        };
    }
}
#endif

The issue is, using SyntaxTree.VisualStudio.Unity.Bridge; fails to compile due to the error error CS0246: The type or namespace name 'SyntaxTree' could not be found (are you missing a using directive or an assembly reference?).

I have checked both Unity and Visual Studio that the Visual Studio Tools for Unity are installed and enabled.

enter image description here

Why is the code failing to compile? Am I missing something that is preventing it from compiling?

Upvotes: 1

Views: 1502

Answers (1)

Dan
Dan

Reputation: 7744

Just incase anyone else has this issue.

This issue was being caused by the scripts position. The script has to be under the Editor folder, otherwise the script won't work as expected.

Credits to therealjohn for pointing it out here.

Upvotes: 1

Related Questions