简体   繁体   English

2个项目1个解决方案共享课程?

[英]2 projects 1 solution- sharing classes?

I am new to windows mobile development and also Visual Studio. 我是Windows移动开发和Visual Studio的新手。

I am developing a web service as well as a mobile application. 我正在开发一个Web服务以及一个移动应用程序。 I have the 1 solution, but 2 different projects. 我有1个解决方案,但有2个不同的项目。

I have created a class in the web service (say project 1), but want to be able to use this class in the mobile application (say project 2). 我在Web服务中创建了一个类(比如项目1),但希望能够在移动应用程序中使用这个类(比如项目2)。

Do I have to basically create a copy of it and reference it in the other project? 我是否必须基本上创建它的副本并在其他项目中引用它?

There are two possible solutions: 有两种可能的解决方案:

  1. Create a third project to contain the shared class and add it as a reference in the other two. 创建第三个项目以包含共享类,并将其作为参考添加到另外两个中。
  2. Keep the class in a single file, but add it to each project as a link, as explained here . 保持类在一个单一的文件,但将其添加到每个项目为纽带,为解释在这里

No, you do not need to create copy. 不,您不需要创建副本。 Instead, add a reference to project1 in the project2 . 而是在project2添加对project1project2

Right-click [References->Add Reference...] in project2 , pick the "Projects" tab, select project1 , and click [OK]. 右键单击project2 [References-> Add Reference ...],选择“Projects”选项卡,选择project1 ,然后单击[OK]。

make your common class as a class library and save it in the form of .dll 将您的公共类作为类库并以.dll的形式保存

whenever you require that class just add its reference to your project and use it :) 每当你需要该类只是添加它对你的项目的引用并使用它:)

This is called re-use one of the best feature of OOPS 这被称为重用OOPS的最佳功能之一

it defeats the purpose of SOA... It becomes Tightly coupled project. 它挫败了SOA的目的......它变成了紧密耦合的项目。 One should not add.. Two different layers.. "add as a reference". 一个不应该添加..两个不同的层..“添加作为参考”。

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

相关问题 在解决方案中的多个项目之间共享LINQ-to-SQL类/模型 - Sharing LINQ-to-SQL classes/models between multiple projects in a solution 在解决方案中共享项目之间的程序集 - Sharing assemblies between projects in a solution 跨解决方案与.Net Core,WPF和Xamarin的多个项目共享图像和类 - Sharing images and classes across Solution with Multiple Projects for .Net Core, WPF and Xamarin 在所有解决方案项目中共享域模型对象 - Sharing Domain model objects in all solution projects 解决方案中的项目之间共享MasterPage的问题 - Issue with sharing MasterPage between projects in Solution 在一个解决方案中处理多个项目中的通用类 - Handling common classes in multiple projects in a single solution 在没有 Visual Studio 的情况下跨项目共享类 - Sharing classes across projects without Visual Studio 跨解决方案在不同项目中将资源 (Resx) 文件作为链接项共享 - Sharing Resource (Resx) file as a linked item in different projects across solution 在项目之间共享C#中的代码而不公开类 - Sharing code in C# between projects without making classes public WPF 多个项目共享同一个主窗口的空白解决方案 - WPF Blank Solution with multiple projects sharing same MainWindow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM