几个项目之间共享C#类的源代码 [英] Share c# class source code between several projects

查看:1289
本文介绍了几个项目之间共享C#类的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个类,将在我的应用程序处理内部记录。
现在我想在另一个新的,完全不同的项目中使用这个类。

I have written a class that will handle internal logging in my application. Now I want to use this class in another new and totally separate project.

我可以简单地将文件复制到新的项目文件夹,但我想只有拥有它的一个副本,保持这样在这一切的变化将适用于这两个项目在一段时间。

I could simply copy the file to the new project folder, but I would like to only have one copy of it to maintain so that all changes in it will apply to both projects over time.

我可以使用添加现有文件,哪来我把文件,以便在下一次开发人员知道,这是必需的。我曾经有此共享文件夹,但有一次,文件夹不带入下一个开发计算机。

I can use the "add existing file", but where do I put the file so that the next developer knows that it is required. I have once had a "shared" folder for this but one time that folder was not brought into the next development computer.

什么是组织这次这样,最好的办法它使新的维护者最有意义,最大限度地减少对项目的链接断开的风险。

What is the best way to organize this so that it makes most sense for new maintainers and minimizes the risk for broken links in projects.

推荐答案

您可以创建一个具有库项目该类这样你所要做的就是添加到项目的引用

You could create a library project that has this class this way all you have to do is add a reference to that project.

如果这是没有选择,你可以使用上点右键 - >添加现有项 - >添加为链接这样你只需要代码的一个副本,但它可以在多个项目存在。

If that is no option you could use "Right click -> add existing item -> Add as link" this way you only have one copy of the code but it can exist in multiple projects.

这篇关于几个项目之间共享C#类的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆