MonoTouch 和 MonoForAndroid 之间的代码共享 [英] Code sharing between MonoTouch and MonoForAndroid

查看:15
本文介绍了MonoTouch 和 MonoForAndroid 之间的代码共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MonoTouch 和 Mono For Android 项目之间共享业务逻辑 c# 代码的最佳做法是什么?

What would be the best practice to share busines logic c# code between MonoTouch and Mono For Android projects?

最初,我的问题是关于物理文件共享:

Edited: Initially, my question was about the physical file sharing:

  1. 您建议使用什么:网络文件共享或一些代码版本控制(git,svn)?就我而言,我使用的是两个工作站 -Mac (MonoDevelop with MonoTouch) 和 PC (Visual Studio withMonoDroid).
  2. 解决方案/项目文件夹结构如何?在"博客帖子:Xamarin 2012 年世界移动大会非官方会议应用发布!"示例结构相当混乱:多个解决方案在一个文件夹中,然后不同的平台项目在一个文件夹中具有不同文件夹和项目名称的子文件夹.它不能在本地完成与IDE.他们是否手动编辑解决方案文件的内容和文件夹名称在 IDE 环境之外?
  3. 对于通用代码的项目,需要什么样的配置文件(模板)利用?Monotouch 有几个:Empty Project、MonoTouch Library项目和 MonoTouch 绑定项目?在 Android 中,我认为 -Android 类库?
  1. What do you propose to use: network file sharing or some code version control (git, svn)? In my case I am using two workstations - Mac (MonoDevelop with MonoTouch) and PC (Visual Studio with MonoDroid).
  2. What about Solution/Project folder structure? In "Blog Post: Xamarin Mobile World Congress 2012 Unofficial Conference App Released!" example structure is quite confusing: several solutions in one folder and then different platform projects in one subfolder with different folder and project names. It can not be accomplished nativly with IDE. Are they editing content of solution files and folder names manualy outside of IDE environment?
  3. And for projects of common code what kind of profile (template) to use? Monotouch has several: Empty Project, MonoTouch Library Project and MonoTouch Binding Projects? In Android i supose - Android class library?

推荐答案

这是一个非常普遍的问题,但这里有一些资源可以帮助您入门:

This is a very general question, but here are a few resources that may help you get started:

  1. 视频:跨平台移动开发
  2. 博客帖子:适用于 Windows Phone 7、MonoDroid 及更高版本的共享库
  3. 图书:使用 C# 进行移动开发
  4. 博文:Xamarin 世界移动大会 2012 非官方会议应用发布!

编辑(回答您的新问题)

  1. 跨项目链接文件背后的想法是文件只有一个实际副本,而不必自己管理多个副本并使它们保持同步.该文件实际上仅存在于一个项目中并链接到其他项目中,但在编译项目时,它会将文件视为实际存在的文件.

  1. The idea behind linking files across projects is that there is only one actual copy of the file, rather than having to manage multiple copies and keep them in sync yourself. The file will actually exist in just one project and be linked into the others, but when the projects are compiled it treats the file as if it were actually there.

我不能确切地说出他们是如何创建文件夹结构的,但我知道在很多情况下我会手动编辑项目或解决方案文件以获得我想要的文件夹结构,因为没有办法单独通过 IDE 获得我想要的东西.这实际上归结为您希望如何构建文件夹的个人偏好.

I can't speak to exactly how they created their folder structure, but I know there have been many cases where I would manually edit project or solution files to get the folder structure I want, because there was no way to get what I wanted through the IDE alone. This really boils down to personal preference on how you want your folders to be structured.

最后,您需要的是针对您想要定位的每个平台的类库项目.使用链接文件方法时,完全取决于您放置物理文件的位置.我经常使用的一种方法是实际创建一个标准的 .NET 4.0 类库,将文件放在那里,然后将它们链接到我的 Mono for Android 和 MonoTouch 类库中.如果您只关心针对 iOS 和 Android,那可能会比它的价值更麻烦,您可以将文件放在一个项目中,然后将它们链接到另一个项目.

In the end, what you need is a class library project for every platform you want to target. When going with the linked file approach, it's totally up to you where you put the physical files. One approach I use often is to actually create a standard .NET 4.0 class library, put the files in there, and then link them into my Mono for Android and MonoTouch class libraries. If all you care about is targeting iOS and Android, that may be more trouble than it's worth, and you can just let the files live in one project and link them into the other.

这篇关于MonoTouch 和 MonoForAndroid 之间的代码共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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