繁体   English   中英

Visual Studio停止调试统一项目

[英]Visual Studio stops debugging unity project

设置: Unity 2017.4.16f1 / 2018.2.18f1

我有一个使用.Net编写的自己的C#库。 该库在Winforms应用程序中运行良好。 通常,它联系服务器应用程序并获取一些数据。

现在我们要在Unity中可视化数据。 为此,我遵循了本指南: https : //docs.unity3d.com/Manual/UsingDLL.html 简而言之:将库拖放到资产文件夹中,添加新脚本并访问该库。 我的第一个问题是兼容性。 因为我首先使用Unity 2017.4.16f1 ,所以我需要将该库从.Net 4.7.2降级到.Net 4.6 ,并将项目设置更改为相同的.Net框架。 摆脱了所有编译器错误之后,我遇到了当前的问题。

我将Visual Studio 2017附加到unity设置断点,并在Unity启动该应用程序。 断点是在我的自定义库中第一次调用函数时。 达到断点。 但是,如果我说“ Step over”(通过单击或F10),则活动线路不会切换,而我会返回Unity 就像我从未开始调试一样。 Unity继续前进,什么都没有发生。

之后,我使用Unity 2018.2.18f1尝试。 但是,存在相同的问题。 没有调用该库。

关于一些兼容性问题,我构建了Unity项目。 没有错误发生。 最后,我将外部库简化为基本级别。 但是我又得到了这种奇怪的行为。 下面是统一脚本和自定义库中的示例类。 感谢您的每条建议。

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

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;
    }
}

核心问题是依赖性。 我将库中的依赖项与Visual Studio中统一项目中的依赖项进行了比较。 事实证明,在Unity中未链接库: System.Data.DataSetExtension 有两种解决方案:

A)如果您不需要它们,请在您的资料库中省略它们。 删除库中的引用,然后再次编译

B)或者如果您需要它们,并且它是'.Net'的一部分,请执行以下操作(未测试):

请参阅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. 在资产根目录中添加一个名为mcs.rsp的文件

  2. 插入-r:System.Data.DataSetExtension行(获取所需引用的名称)

  3. 重新启动Unity

暂无
暂无

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

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