Visual Studio 2008 - 两个项目是否可以共享公共类?

发布于 2024-09-01 07:09:06 字数 192 浏览 3 评论 0原文

在 Visual Studio 2008 中,我知道可以使用一个解决方案来处理两个(或更多)项目。

是否可能或项目如何共享公共类文件?

例如->项目 1 有一个日志文件处理类。项目2可以参考一下吗?

我的希望是增加代码重用并避免需要维护同一事物的两个副本。

目标是 Winforms C# (3.5)

In Visual Studio 2008 I know its possible to have one solution with two (or more) projects.

Is it possible OR How is it possible for the projects to share common class files?

For example -> Project 1 has a log file handling class. Can Project 2 reference it?

My hope is to increase code re-use and avoid two copies of the same thing that need to be maintained.

The target is Winforms C# (3.5)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

尴尬癌患者 2024-09-08 07:09:07

是的,一个项目可以引用另一个项目。只需选择添加引用>即可Projects 并选择要引用的项目。

Yes, one project can reference the other one. Simply choose Add reference > Projects and select the project to be referenced.

杀お生予夺 2024-09-08 07:09:07

您可能希望将非应用程序特定的通用功能移至位于其自己的开发轨道上的库,并从两者中引用该库。

You may want to move non-application specific common functionality to a library that is on it's own development track and reference that from both.

懒猫 2024-09-08 07:09:07

是的,这绝对是可能的。您需要从项目 2 添加对项目 1 的引用(在解决方案资源管理器中右键单击项目 2,选择“添加引用...”,然后在“项目”选项卡下选择项目 1)。

不要忘记项目 1 和项目 2 的代码可能位于不同的命名空间中。您需要添加适当的 using 语句。

Yes, this is definitely possible. You need to add a reference to Project 1 from Project 2 (right-click Project 2 in the Solution Explorer, choose "Add Reference...", and choose Project 1 under the "Projects" tab).

Don't forget that the code for Project 1 and Project 2 is likely to be in different namespaces. You'll need to add the appropriate using statement(s).

∞觅青森が 2024-09-08 07:09:07

您实际上并不希望该类位于两个项目中。您希望它位于项目 A 中,然后添加从项目 B 到项目 A 的引用。这将允许您在两个项目中使用该类。

You don't actually want the class to be in two projects. You want it to be in project A, and then add a reference from project B to project A. This will allow you to use the class in both projects.

川水往事 2024-09-08 07:09:07

右键单击您想要使用公共类的项目,然后选择“添加引用...”。在出现的对话框中,选择“项目”选项卡,然后选择包含公共类的项目。

Right click on the project that you want to use the common classes nd select "Add Reference...". In the dalog that appears, choose the "Projects" tab and select the project that contains the common classes.

时光沙漏 2024-09-08 07:09:07

您还可以编译您想要使用的类并将其放入全局程序集缓存

You can also compile your classes you wanna use an put the to the global assembly cache

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文