找不到命名空间名称语法树 [英] The namespace name 'SyntaxTree' could not be found

查看:60
本文介绍了找不到命名空间名称语法树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在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

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

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

为什么代码无法编译?我是否遗漏了阻止它编译的内容?

推荐答案

以防其他人遇到此问题。

此问题是由脚本位置引起的。脚本必须位于Editor文件夹下,否则脚本不会按预期工作。

感谢therealjohn指出here

这篇关于找不到命名空间名称语法树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆