简体   繁体   English

将来将Xamarin添加到Visual Studio C#项目中

[英]Adding Xamarin to a Visual Studio C# project in future

We are looking to create a Visual Studio C# project that will be initially released as a Windows application. 我们希望创建一个Visual Studio C#项目,该项目最初将作为Windows应用程序发布。 However, in future we would like to release on iOS and Android platforms using the Xamarin extension. 但是,将来我们希望使用Xamarin扩展在iOS和Android平台上发布。

We plan to have a core application that is kept separate from the GUI code as much as possible to make multi-platform development more convenient in future. 我们计划有一个尽可能远离GUI代码的核心应用程序,以使将来的多平台开发更加方便。

Is this a good plan, or is it better to incorporate Xamarin into the project from the beginning? 这是一个好的计划,还是从一开始就将Xamarin纳入该项目更好?

We haven't used Xamarin before, and we're hoping to minimise refactoring of our code. 我们以前从未使用过Xamarin,我们希望最大程度地减少代码的重构。

I think most developers would prefer to add the Xamarin project from the beginning but I started a project this way as well and I'd reconsider this as a successful one. 我认为大多数开发人员都希望从一开始就添加Xamarin项目,但是我也以这种方式启动了一个项目,因此我认为这是一个成功的项目。 However you should have some experienced developers which can handle UI abstractions and not put their code in the UI layer. 但是,您应该拥有一些经验丰富的开发人员,他们可以处理UI抽象,而不必将其代码放在UI层中。 Maybe you should look at frameworks like MVVM cross if you want to go cross platform. 如果您想跨平台运行,也许应该看看像MVVM cross这样的框架。

However, Xamarin evolved as well and there's not just Xamarin.iOS and Xamarin.Andoird anymore. 但是,Xamarin也在发展,不仅有Xamarin.iOS和Xamarin.Andoird。 So they released their fantastic framework Xamarin.Forms a few months ago. 因此,他们在几个月前发布了出色的框架Xamarin.Forms By using it, you'll be able to reuse huge amount of your code - even the UI-code. 通过使用它,您将能够重用大量代码,甚至包括UI代码。 So if your Windows Application is either a Windows Phone Application or a Modern UI-App and not a WinForms app (which not supported with Xamarin.Forms), it might be the best option for you. 因此,如果您的Windows应用程序是Windows Phone应用程序或Modern UI-App,而不是 WinForms应用程序(Xamarin.Forms不支持),则它可能是您的最佳选择。

.Net Framework Portble Class Library is what you need. 您需要的是.Net Framework Portble类库。 Code that are shared amongst platforms should be implemented using PCL. 平台之间共享的代码应使用PCL实现。 What I do for my organisation is that I created one solution for each platform and add reference to PCLs that contain our common code. 我为我的组织所做的是,我为每个平台创建了一个解决方案,并添加了对包含我们的通用代码的PCL的引用。 Our PCLs can run in Windows, Android and iOS. 我们的PCL可以在Windows,Android和iOS上运行。

https://msdn.microsoft.com/en-us/library/gg597391%28v=vs.110%29.aspx https://msdn.microsoft.com/zh-CN/library/gg597391%28v=vs.110%29.aspx

Another way to do it is to write c# classes and add class references to your platform-specific code. 另一种方法是编写c#类并将类引用添加到特定于平台的代码中。 However, if you go with this approach, each time you make a modification to the class, you need to make sure it builds in all platforms. 但是,如果采用这种方法,则每次对类进行修改时,都需要确保它可以在所有平台上构建。

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

相关问题 使用c#将Access数据库添加到Visual Studio 2010中的项目中 - Adding Access Database to Project in Visual Studio 2010 using c# 将我自己的C#项目配置添加到MSBuild / Visual Studio中 - Adding my own configuration for a C# project into MSBuild / Visual Studio 将 dll 引用添加到 github 上可见的 Visual Studio c# 项目 - Adding dll reference to visual studio c# project visible on github 在Xamarin C#Visual Studio中创建TableView - Create TableView in Xamarin C# Visual Studio 将ac#project添加到visual studio 2008中的现有c ++项目中 - adding a c# project to an existing c++ project in visual studio 2008 在Visual Studio 2012中将C#对象添加到VB Web项目中。获取C#模板吗? - adding C# objects to a VB web project in Visual Studio 2012. Getting C# templates? C# 文件(CodeBehind 类)从 Visual Studio 中的项目中消失 - Xamarin - C# file (CodeBehind class) disappearing from project in Visual Studio - Xamarin c# Visual Studio ...以编程方式添加引用 - c# Visual Studio ...adding references programmatically 在 c# (visual studio) 中添加 2 个双数 - Adding 2 double numbers in c# (visual studio) 通过发布完成C#Visual Studio项目 - Completing a C# Visual Studio Project by publishing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM