如何在 Xamarin.Android 项目中调试引用的程序集 [英] How to debug a referenced assembly in Xamarin.Android project

查看:32
本文介绍了如何在 Xamarin.Android 项目中调试引用的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 Visual Studio 2010 测试 Xamarin.Android.

I am testing out Xamarin.Android via Visual Studio 2010.

我的 Xamarin.Android VS2010 解决方案包含两个项目:Android 项目和一个项目(在本文中我将其称为 MyProject),它为我正在制作的演示应用程序执行所有业务逻辑 - Android 项目参考MyProject 项目/程序集).

My Xamarin.Android VS2010 Solution contains two projects: The Android project and a project (I'll call it MyProject for this post) that does all the business logic for the demo app that I'm making - The Android project references the MyProject project/assembly).

当我运行应用程序时,我在 MyProject 中收到异常错误,因此,我想进入 MyProject 并调试问题.

When I run the appliation, I am receiving an exception error in MyProject and, so, I would like to step into MyProject and debug the problem.

但是,当我调试时,VS2010 并没有进入 MyProject.

However, when I debug, VS2010 is not stepping into MyProject.

例如:

在我的 Android 项目中,我在异常位置有一个断点:

In my Android project I have a breakpoint at the location of the exception:

MyProject mp= new MyProject();
mp.DoSomething(); // Exception is thrown here, breakpoint is set here, but VS doesn't step into the MyProject code. The debugger gets stuck here and displays exception info in the Output window.

我需要做什么才能在我的 VS2010 Mono Android 项目中调试引用的项目/程序集?

What do I need to do to debug a referenced project/assembly in my VS2010 Mono Android project?

推荐答案

我无法调试引用的程序集的原因是我引用的程序集是一个 .NET 程序集 - 一个用 C# 编写的程序集,它引用了 .NET 程序集.

The reason I was unable to debug the referenced assembly was due to the fact that my referenced assembly was a .NET assembly - an assembly written in C# which referenced .NET assemblies.

作为 Xamarin.Android 开发的新手,我假设我可以创建一个 Android 项目,然后简单地将现有的 .NET 项目引用到该 Android 项目 - 事实并非如此.

Being new to Xamarin.Android development, I assumed that I could create an Android project and then simply reference an existing .NET project to the Android project - this is not the case.

为了在 Android 项目中引用 .NET 程序集(从而调试 .NET 程序集),我必须:

In order to reference a .NET assembly in an Android project (and thereby debug the .NET assembly) I had to:

  1. 在 Visual Studio(或 Xamarin Studio)中,创建一个新的 Android 类库项目
  2. 将 .NET 项目中的所有 .cs 文件复制到新创建的 Android 类库中
  3. 构建/编译 Android 类库.此时,您可能需要手动添加对默认情况下未添加到项目中的 Mono 程序集的引用.例如:我必须手动添加 Mono System.Data 程序集.
  4. 在原始Android项目中,引用Android类库
  5. 完成

要理解的重要一点(我没有理解)是 Xamarin 创建了与 .NET 程序集相对应的 Mono 程序集.Mono 程序集存在于 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\ 中(在我的机器上),而 .NET 程序集存在(在我的机器上)在(即在 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 目录中找到的程序集)"中.

The important thing to understand (which I didn't) is that Xamarin has created Mono assemblies which correspond to the .NET assemblies. The Mono assemblies exist (on my machine) in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\ while the .NET assemblies exist (on my machine) in '(i.e. assemblies found within the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 directory)'.

请注意 - 如果 Android 项目引用使用 .NET 程序集的程序集/项目,您将收到一条警告,指出

On that note - If an Android project is referencing an assembly/project that uses the .NET assemblies, you will receive a Warning that states

无法引用项目‘MyProject’.引用的项目是目标到不同的框架系列 (.NETFramework)"

"The project 'MyProject' cannot be referenced. The referenced project is targeted to a different framework family (.NETFramework)"

这篇关于如何在 Xamarin.Android 项目中调试引用的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆