【问题标题】:The namespace name 'SyntaxTree' could not be found找不到命名空间名称“语法树”
【发布时间】:2019-10-30 09:22:53
【问题描述】:

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

为什么代码编译失败?我是否遗漏了阻止其编译的内容?

【问题讨论】:

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


【解决方案1】:

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

这个问题是由脚本位置引起的。脚本必须在Editor 文件夹下,否则脚本将无法按预期运行。

感谢therealjohn 指出here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 2016-06-14
    相关资源
    最近更新 更多