"Multiple assemblies with equivalent identity have been imported" 在 VS2015 中使用 Unity 生成的 csproj
"Multiple assemblies with equivalent identity have been imported" in VS2015 with a Unity generated csproj
我在 Unity 2018.1 中启动了一个新的 .NET 4.6 项目,当我尝试在 Visual Studio 2015 年构建它时,我得到 "CS1703: Multiple assemblies with equivalent identity have been imported" 加载和加载的 .NET 程序集,所有这些都是 BCL 的一部分。项目中唯一的代码是一个空 class。 Unity控制台没有报错。
简单的重现步骤(见最后的版本信息):
- 创建一个新的 Unity 项目
- 在播放器设置中将脚本运行时级别设置为 .NET 4.x
- 添加新的 C# 脚本
- 在 VS 中打开项目
- 尝试构建它
如果这是一个普通项目,我会删除重复的引用,但 Unity 会不断重新生成此 .csproj。
版本信息:
- 统一:2018.1.0f2
- Visual Studio 2015 年:更新 3 (14.0.25431.01)
- Visual Studio Unity 工具:3.7.0.1
这似乎是 Unity 2018 中关于如何生成 Visual Studio 项目文件的已知问题。我刚刚观察到 Unity 2018.1.2f1 和 Visual Studio 2015 Update 3 (14.0.25431.01).
存在同样的问题
有人在 Unity forum here 上发布了看似相同的问题。微软的 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
我在 Unity 2018.1 中启动了一个新的 .NET 4.6 项目,当我尝试在 Visual Studio 2015 年构建它时,我得到 "CS1703: Multiple assemblies with equivalent identity have been imported" 加载和加载的 .NET 程序集,所有这些都是 BCL 的一部分。项目中唯一的代码是一个空 class。 Unity控制台没有报错。
简单的重现步骤(见最后的版本信息):
- 创建一个新的 Unity 项目
- 在播放器设置中将脚本运行时级别设置为 .NET 4.x
- 添加新的 C# 脚本
- 在 VS 中打开项目
- 尝试构建它
如果这是一个普通项目,我会删除重复的引用,但 Unity 会不断重新生成此 .csproj。
版本信息:
- 统一:2018.1.0f2
- Visual Studio 2015 年:更新 3 (14.0.25431.01)
- Visual Studio Unity 工具:3.7.0.1
这似乎是 Unity 2018 中关于如何生成 Visual Studio 项目文件的已知问题。我刚刚观察到 Unity 2018.1.2f1 和 Visual Studio 2015 Update 3 (14.0.25431.01).
存在同样的问题有人在 Unity forum here 上发布了看似相同的问题。微软的 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