简体   繁体   English

Visual Studio停止调试统一项目

[英]Visual Studio stops debugging unity project

Setup: Unity 2017.4.16f1 / 2018.2.18f1 设置: Unity 2017.4.16f1 / 2018.2.18f1

I've got an own written C# library, using .Net . 我有一个使用.Net编写的自己的C#库。 The library works fine in a Winforms application. 该库在Winforms应用程序中运行良好。 In general it contacts a server application and fetches some data. 通常,它联系服务器应用程序并获取一些数据。

Now we want to visualize the data within Unity. 现在我们要在Unity中可视化数据。 For that I followed this guide: https://docs.unity3d.com/Manual/UsingDLL.html . 为此,我遵循了本指南: https : //docs.unity3d.com/Manual/UsingDLL.html In short: Drag and drop the library in the asset folder, add a new script and access the library. 简而言之:将库拖放到资产文件夹中,添加新脚本并访问该库。 My first problem was the compatibility. 我的第一个问题是兼容性。 Because, I used Unity 2017.4.16f1 first, I needed to downgrade the library from .Net 4.7.2 to .Net 4.6 and change the project settings to the same .Net framework. 因为我首先使用Unity 2017.4.16f1 ,所以我需要将该库从.Net 4.7.2降级到.Net 4.6 ,并将项目设置更改为相同的.Net框架。 After getting rid of all the compiler errors, I ran into my current Problem. 摆脱了所有编译器错误之后,我遇到了当前的问题。

I attached Visual Studio 2017 to unity set up my breakpoint and started the app within Unity . 我将Visual Studio 2017附加到unity设置断点,并在Unity启动该应用程序。 The breakpoint is on the first call of a function from my custom library. 断点是在我的自定义库中第一次调用函数时。 The breakpoint is reached. 达到断点。 But if i say 'Step over' (either via click or F10) the active line doesn't switch and I get back to Unity . 但是,如果我说“ Step over”(通过单击或F10),则活动线路不会切换,而我会返回Unity It's like i never started debugging. 就像我从未开始调试一样。 Unity goes on like nothing happened. Unity继续前进,什么都没有发生。

After that i tried it with Unity 2018.2.18f1 . 之后,我使用Unity 2018.2.18f1尝试。 However, there is the same problem. 但是,存在相同的问题。 The library isn't called. 没有调用该库。

Regarding some compatibility issues, I built the Unity project. 关于一些兼容性问题,我构建了Unity项目。 No error occurs. 没有错误发生。 Finally I stripped down the external library to a basic level. 最后,我将外部库简化为基本级别。 But again I got this strange behavior. 但是我又得到了这种奇怪的行为。 Below is the script for unity and an example class from the custom library. 下面是统一脚本和自定义库中的示例类。 Thank you for every advice. 感谢您的每条建议。

C# : C#

[Serializable]
public class PostgreSQLParameters

[XmlElement(ElementName = "PostgreSQL_User", IsNullable = false)]
public string UserName
{
    get
    {
        return this.userName;
    }

    set
    {
        if (this.userName == value)
            return;
        this.userName = value;
        this.OnPropertyChanged();
    }
}

public PostgreSQLParameters()
{ }

Unity : Unity

void Start () {

    string cwd = Directory.GetCurrentDirectory();
    string pathVariable = Environment.GetEnvironmentVariable("PATH");

    try
    {
        //this line has the break point, untill here all is ok
        //after the Debug steps in, I hit F10 here to get to the next line,
        //which should be the bracket befor the catch

        PostgreSQLParameters parameter = new PostgreSQLParameters();
    }  // The cursor should be here after hitting F10, but disappears only
    catch (Exception)
    {

        throw;
    }
}

The core problem are the dependencies. 核心问题是依赖性。 I compared the dependencies in my library, with them from the unity project within Visual Studio. 我将库中的依赖项与Visual Studio中统一项目中的依赖项进行了比较。 It turns out on library wasn't linked in Unity: System.Data.DataSetExtension . 事实证明,在Unity中未链接库: System.Data.DataSetExtension There are two solutions: 有两种解决方案:

A) If you don't need them, omit them in your library. A)如果您不需要它们,请在您的资料库中省略它们。 Delete the reference in the library and compile again 删除库中的引用,然后再次编译

B) Or if you need them and it's part of '.Net' do the following (not tested): B)或者如果您需要它们,并且它是'.Net'的一部分,请执行以下操作(未测试):

See https://docs.microsoft.com/en-us/visualstudio/cross-platform/unity-scripting-upgrade?view=vs-2017#adding-assembly-references-when-using-the-net-4x-api-compatibility-level 请参阅https://docs.microsoft.com/zh-cn/visualstudio/cross-platform/unity-scripting-upgrade?view=vs-2017#adding-assembly-references-when-using-the-net-4x-api -compatibility级

  1. add a file, called mcs.rsp, in the asset root 在资产根目录中添加一个名为mcs.rsp的文件

  2. Insert the line -r:System.Data.DataSetExtension (take the name of the reference you need) 插入-r:System.Data.DataSetExtension行(获取所需引用的名称)

  3. Restart Unity 重新启动Unity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM