问题描述
在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:
- 您打算使用什么:网络文件共享或一些代码版本控制(git,svn)?就我而言,我使用的是两个工作站-Mac(带有MonoTouch的MonoDevelop)和PC(带有Visual Studio的Visual Studio)MonoDroid).
- 解决方案/项目文件夹结构如何?在博客文章: Xamarin世界移动通信大会2012非官方会议应用发布!"示例结构非常混乱:一个文件夹中包含多个解决方案,然后一个文件夹中包含不同的平台项目文件夹和项目名称不同的子文件夹.不能天真地完成它与IDE.他们是否手动编辑解决方案文件和文件夹名称的内容在IDE环境之外?
- 对于通用代码项目,要使用什么样的配置文件(模板)使用? Monotouch有几个:空项目,MonoTouch库项目和MonoTouch绑定项目?在Android中,我随身-Android类库?
- What do you propose to use: network file sharing or some codeversion control (git, svn)? In my case I am using two workstations - Mac (MonoDevelop with MonoTouch) and PC (Visual Studio withMonoDroid).
- What about Solution/Project folder structure? In"Blog Post: Xamarin Mobile World Congress 2012 UnofficialConference App Released!" example structure is quite confusing:several solutions in one folder and then different platform projects in onesubfolder with different folder and project names. It can not be accomplished nativlywith IDE. Are they editing content of solution files and folder names manualyoutside of IDE environment?
- And for projects of common code what kind of profile (template) touse? Monotouch has several: Empty Project, MonoTouch LibraryProject 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:
- 视频:跨平台移动开发
- 博客文章: Windows Phone 7,MonoDroid和更高版本的共享库
- 图书:使用C#进行移动开发
- 博客文章: Xamarin Mobile World Congress 2012非官方会议应用程序已发布!
- Video: Cross-platform Mobile Development
- Blog Post: Shared Libraries For Windows Phone 7, MonoDroid and Beyond
- Book: Mobile Development with C#
- Blog Post: Xamarin Mobile World Congress 2012 Unofficial Conference App Released!
编辑(回答新问题)
-
跨项目链接文件的想法是,文件只有一个实际副本,而不必管理多个副本并使自己保持同步.该文件实际上仅存在于一个项目中,并链接到其他项目中,但是在编译项目时,它将文件视为实际存在.
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之间的代码共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!