简体   繁体   English

如何在项目之间共享代码和资源

[英]How to share code and resources between projects

I have two projects named Project 1 and Project 2. I am porting my application from iOS to WP8 and I have ported my iOS_Project 1 to WP8_Project 1. In iOS I have the flexibility to add the files as references and thereby I can achieve code reuse. 我有两个名为Project 1和Project 2的项目。我将应用程序从iOS移植到WP8,并且将iOS_Project 1移植到WP8_Project1。在iOS中,我可以灵活地添加文件作为引用,从而可以实现代码重用。 I would like to perform the same process in WP8, but I couldn't find proper help and here's the question. 我想在WP8中执行相同的过程,但是我找不到适当的帮助,这就是问题所在。 (Here I want to refer all the classes, images and xaml files like MainPage.xaml) (这里我想引用所有类,图像和xaml文件,例如MainPage.xaml)

I know pretty sure about one thing that wpf/forms/.NET projects differ with WP8 structure. 我很确定wpf / forms / .NET项目与WP8结构不同的一件事。 Please do provide some help. 请提供一些帮助。

Thanks. 谢谢。

You can use references in Visual Studio 2012 - there is no problem. 您可以在Visual Studio 2012中使用引用-没问题。 However, PCL ( Portable Class Library ) is a better solution. 但是,PCL( 可移植类库 )是更好的解决方案。 Here is example how to add files as link in Visual Studio 2012. 这是在Visual Studio 2012中如何将文件添加为链接的示例。

When you have add your item to one project, select the option to Add Existing Item to the other project. 将项目添加到一个项目后,选择将现有项目添加到另一个项目的选项。 Navigate to the item you want to add and then you should find a drop-down arrow on the appropriate button to allow you to add the item as a link. 导航到要添加的项目,然后您将在适当的按钮上找到一个下拉箭头,以允许您将该项目添加为链接。 That means that there will only ever be one copy of that item but it will be used in both projects. 这意味着该项目将永远只有一个副本,但是将在两个项目中使用。

That said, if possible, I would suggest that you break the common functionality out into a library project that you then reference in both the other projects. 就是说,如果可能的话,我建议您将通用功能分解为一个库项目,然后在其他两个项目中进行引用。 If you create a portable library then you could use it in a Windows 8 app as well. 如果创建可移植库,则也可以在Windows 8应用程序中使用它。

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

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