找不到名称空间名称“ SyntaxTree”

时间:2019-10-30 09:22:53

标签: c# visual-studio unity3d namespaces visual-studio-2019

我正在Unity 2019.2.3f1中进行开发。我正在尝试编写一个可以Customize project files created by VSTU的脚本。万一链接被删除,我将包含一个与链接中的脚本非常相似的脚本。

#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

问题是using SyntaxTree.VisualStudio.Unity.Bridge;由于错误error CS0246: The type or namespace name 'SyntaxTree' could not be found (are you missing a using directive or an assembly reference?)而无法编译。

我已经检查了Unity和Visual Studio是否已安装并启用了Visual Studio Tools for Unity。

enter image description here

为什么代码无法编译?我是否缺少阻止其编译的内容?

1 个答案:

答案 0 :(得分:0)

以防万一其他人遇到这个问题。

此问题是由脚本位置引起的。该脚本必须位于Editor文件夹下,否则该脚本将无法正常工作。

therealjohn指出来向here致谢。

相关问题