【问题标题】:Unity to Visual Studio : Multiple assemblies with equivalent identity have been importedUnity 到 Visual Studio:已导入具有等效标识的多个程序集
【发布时间】:2016-07-24 02:36:29
【问题描述】:

我正在设计一个在 Microsoft HoloLens 上运行的应用程序,使用 Unity 进行用户交互。 应用程序连接到 asmx 网络服务以检索数据。

我有一个 C# 测试程序来测试网络服务的连接和数据检索。

然后我按照本教程生成了一个基于 webservice 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 编辑器时,我的应用程序连接到 Web 服务并毫无问题地检索数据。

下一步,我按照本教程从 Unity (http://hololenshelpwebsite.com/Blog/EntryId/1006/HoloLens-Hello-World) 制作 HoloLens 应用程序

虽然它适用于他们自己的 Hello World,但当我尝试从统一构建自己的项目时,我收到以下错误:

错误 CS1703:具有相同标识的多个程序集已 进口: 'C:\Users\UserA\.nuget\packages\Microsoft.NETCore.Portable.Compatibility\1.0.0\ref\netcore50\System.dll' 和“J:\Work\MyTestUnity\Assets\System.dll”。删除其中一个 重复引用。版权所有 (C) Microsoft Corporation。所有权利 reserved.Microsoft (R) Visual C# 编译器版本 1.3.1.60616

于是我在Editor下添加了一个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();
        };
    }
}

但看起来这没有任何作用。

我现在不知道如何解决这个问题,我真的需要专家的帮助来解决这个问题。

【问题讨论】:

    标签: c# dataset unity5 webservice-client hololens


    【解决方案1】:

    所以... 看起来我们不能再像那样使用 WSDL webservice 了。 微软不久前在更新中放弃了对它的支持。 我看过多篇关于它的文章,但我忘了保留书签。 因此,如果您想查找它,则必须阅读 WUP 文档。

    相反,我们最终使用 UnityWebRequest 和 Coroutines 来处理 Web 服务通信。

    我们还必须更新网络服务以启用 Get/post 调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-01
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多