Reputation: 36851
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):
If this was a normal project I would just remove the duplicated references but this .csproj is continually regenerated by Unity.
Version information:
Upvotes: 4
Views: 3435
Reputation: 68
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
Upvotes: 2