Unity到Visual Studio:已导入多个具有等效标识的程序集
我正在设计一个应用程序,使用Unity在Microsoft HoloLens上运行用户交互。 应用程序连接到asmx webservice以检索数据。Unity到Visual Studio:已导入多个具有等效标识的程序集
我有一个C#测试程序来测试从web服务的连接和数据检索。
我再接着这个教程基于web服务的WSDL(https://www.youtube.com/watch?v=AifcMzEbKnA)
生成一个DLL如果使用下面的脚本生成的dll:
@echo off
if exist "Service.xml" (
del MyOwnWS.wsdl
echo Rename
rename Service.xml MyOwnWS.wsdl
echo.
)
echo WSDL
call wsdl MyOwnWS.wsdl -o:MyOwnWS.cs
echo.
echo DMCS
call dmcs /target:library MyOwnWS.cs -r:System.Web.Services,System.Data
echo.
echo Done
我加system.Data,因为我的web服务从数据库返回DataSet数据。
我将该dll放入Unity项目的Assets文件夹中。 我也不得不丢弃System.Data.dll,System.dll和System.Web.Services.dll(从C:\ Program Files \ Unity Hololens 5.4.0b16-HTP \ Editor \ Data \ Mono \ lib \ mono \ unity文件夹)
当我使用Unity编辑器时,我的应用程序连接到webservice并检索数据没有问题。
下一步,我跟着这个教程,使从团结HoloLens应用(http://hololenshelpwebsite.com/Blog/EntryId/1006/HoloLens-Hello-World)
虽然为自己的Hello World的工作,当我试图从团结我收到以下错误建立自己的项目:
error CS1703: Multiple assemblies with equivalent identity have been imported: 'C:\Users\UserA\.nuget\packages\Microsoft.NETCore.Portable.Compatibility\1.0.0\ref\netcore50\System.dll' and 'J:\Work\MyTestUnity\Assets\System.dll'. Remove one of the duplicate references.Copyright (C) Microsoft Corporation. All rights reserved.Microsoft (R) Visual C# Compiler version 1.3.1.60616
所以我增加了一个ProjectFileHook.cs文件编辑器下,内容如下:
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using UnityEditor;
using SyntaxTree.VisualStudio.Unity.Bridge;
using UnityEngine;
// http://forum.unity3d.com/threads/missing-c-references-to-system-data.11361/
// https://visualstudiogallery.msdn.microsoft.com/8d26236e-4a64-4d64-8486-7df95156aba9
[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 void ProcessNodesWithIncludeAttribute(XDocument document, string localName, string includeValue, Action<XElement> action)
{
var nodes = document
.Descendants()
.Where(p => p.Name.LocalName == localName);
foreach (var node in nodes)
{
var xa = node.Attribute("Include");
if (xa != null && !string.IsNullOrEmpty(xa.Value) && string.Equals(xa.Value, includeValue))
{
action(node);
}
}
}
// Remove System.Data from project (not from file system so Unity can compile properly)
static void RemoveFileFromProject(XDocument document, string fileName)
{
ProcessNodesWithIncludeAttribute(document, "None", fileName, element => element.Remove());
}
// Adjust references, by using the default framework assembly instead of local file (remove the HintPath)
static void RemoveHintPathFromReference(XDocument document, string assemblyName)
{
ProcessNodesWithIncludeAttribute(document, "Reference", assemblyName, element => element.Nodes().Remove());
}
static ProjectFileHook()
{
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
{
var document = XDocument.Parse(content);
RemoveFileFromProject(document, @"Assets\System.Data.dll");
RemoveHintPathFromReference(document, "System.Data");
RemoveFileFromProject(document, @"Assets\System.Web.Services.dll");
RemoveHintPathFromReference(document, "System.Web.Services");
RemoveFileFromProject(document, @"Assets\System.dll");
RemoveHintPathFromReference(document, "System");
var str = new Utf8StringWriter();
document.Save(str);
return str.ToString();
};
}
}
但它看起来像这样的母鹿没什么。
我在迷失如何解决此问题,我真的需要专家帮忙弄明白。
因此... 看起来我们不能再使用WSDL webservice了。 微软不久前在更新中放弃了对它的支持。 我看到了多篇关于它的文章,但我忘了保留一个书签。 所以,如果你想查看它,你将不得不通过WUP文档。
相反,我们最终使用UnityWebRequest和Coroutines来处理Web服务通信。
我们还必须更新web服务才能启用获取/发布呼叫。