这似乎是 Unity 2018 中的一个已知问题,它如何生成 Visual Studio 项目文件。我刚刚观察到 Unity 2018.1.2f1 和 Visual Studio 2015 Update 3 (14.0.25431.01) 存在同样的问题。
有人在此处的 Unity 论坛上发布了似乎相同的问题。Microsoft 的 Sebastien Lebreton 提供了一种解决方法,直到 Unity 解决了问题。将以下脚本添加到项目中名为“Editor”的文件夹中。
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using UnityEditor;
#if ENABLE_VSTU
using SyntaxTree.VisualStudio.Unity.Bridge;
[InitializeOnLoad]
public class ProjectFileHook
{
// necessary for XLinq to save the xml project file in utf8
class Utf8StringWriter : StringWriter
{
public override Encoding Encoding
{
get { return Encoding.UTF8; }
}
}
static ProjectFileHook()
{
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
{
// parse the document and make some changes
var document = XDocument.Parse(content);
var ns = document.Root.Name.Namespace;
document.Root
.Descendants()
.First(x => x.Name.LocalName == "PropertyGroup")
.Add(new XElement(ns + "ImplicitlyExpandNETStandardFacades", "false"),
new XElement(ns + "ImplicitlyExpandDesignTimeFacades", "false"));
// save the changes using the Utf8StringWriter
var str = new Utf8StringWriter();
document.Save(str);
return str.ToString();
};
}
}
#endif