“已导入具有相同标识的多个程序集"在VS2015中,使用Unity生成的csproj [英] "Multiple assemblies with equivalent identity have been imported" in VS2015 with a Unity generated csproj

查看:737
本文介绍了“已导入具有相同标识的多个程序集"在VS2015中,使用Unity生成的csproj的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Unity 2018.1中启动了一个新的.NET 4.6项目,当我尝试在Visual Studio 2015中对其进行构建时,我收到了"CS1703:具有相同标识的多个程序集已导入"的信息.程序集,所有这些都是BCL的一部分.项目中唯一的代码是一个空类. Unity控制台中没有错误.

I've started a new .NET 4.6 project in Unity 2018.1, and when I try to build it in Visual Studio 2015, I get "CS1703: Multiple assemblies with equivalent identity have been imported" for loads and loads of .NET assemblies, all of which are part of the BCL. The only code in the project is an empty class. There are no errors in the Unity console.

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

Easy repro steps (see version info at the end):

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

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

If this was a normal project I would just remove the duplicated references but this .csproj is continually regenerated by Unity.

版本信息:

  • 团结: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)中观察到相同的问题.

This appears to be a known issue in Unity 2018 with how it generates the Visual Studio project files. I just observed the same problem with Unity 2018.1.2f1 and Visual Studio 2015 Update 3 (14.0.25431.01).

有人在

Someone posted what appears to be the same problem on the Unity forum here. Sebastien Lebreton of Microsoft responded with a workaround until Unity fixes the problem. Add the below script into a folder named "Editor" in your project.

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

这篇关于“已导入具有相同标识的多个程序集"在VS2015中,使用Unity生成的csproj的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆