【问题标题】:"Multiple assemblies with equivalent identity have been imported" in VS2015 with a Unity generated csprojVS2015中的“已导入具有相同标识的多个程序集”,带有Unity生成的csproj
【发布时间】:2025-12-24 06:15:11
【问题描述】:

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

【问题讨论】:

    标签: unity3d visual-studio-2015


    【解决方案1】:

    这似乎是 Unity 2018 中生成 Visual Studio 项目文件的一个已知问题。我刚刚观察到 Unity 2018.1.2f1 和 Visual Studio 2015 Update 3 (14.0.25431.01) 存在同样的问题。

    有人在Unity forum here 上发布了看似相同的问题。 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
    

    【讨论】:

      最近更新 更多