4

我在 Unity 2018.1 中启动了一个新的 .NET 4.6 项目,当我尝试在 Visual Studio 2015 中构建它时,我得到“CS1703:已导入具有等效标识的多个程序集”,用于加载和加载 .NET 程序集,所有其中是 BCL 的一部分。项目中唯一的代码是一个空类。Unity 控制台中没有错误。

简单的复制步骤(请参阅最后的版本信息):

  1. 创建一个新的 Unity 项目
  2. 在播放器设置中将脚本运行时级别设置为 .NET 4.x
  3. 添加新的 C# 脚本
  4. 在VS中打开项目
  5. 尝试构建它

如果这是一个普通项目,我只会删除重复的引用,但 Unity 会不断地重新生成这个 .csproj。

版本信息:

  • 统一:2018.1.0f2
  • Visual Studio 2015:更新 3 (14.0.25431.01)
  • 适用于 Unity 的 Visual Studio 工具:3.7.0.1
4

1 回答 1

2

这似乎是 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
于 2018-05-29T21:25:16.683 回答