Visual Studio .NET 中的自定义通用库类

发布于 2024-09-18 00:57:04 字数 578 浏览 3 评论 0原文

我编写了一些用于许多不同项目的类。 例如,我几乎在每个项目中都使用 Library.Controls.FlatButton.cs。 问题是当我将其添加为“现有项目”时;每次都会在我的 Soultion 文件夹中创建/复制该类。每次编辑/更新该类的内容时,我都必须更新每个项目文件夹中的所有 Library.Controls.FlatButton.cs 文件。

我需要能够编辑 FlatButton 类的单个源,并且当我编译/构建项目(使用类文件)时,会更新到该类的新版本。 问题1:有办法做到这一点吗?

我知道我可以将所有这些类收集到一个库项目 (Library.Controls) 中,并将其作为依赖项添加到每个应用程序解决方案中。 问题 2:这是使用单一通用库文件源的唯一方法吗?如果我这样做了;即使我在项目中仅使用了此 FlatButton 类,Library.Controls 命名空间中的所有类都会随每个应用程序一起编译吗?

希望这对你来说很清楚.. 谢谢

I wrote some classes that I use with many different projects.
For example, I use Library.Controls.FlatButton.cs almost in every project.
The problem is when I add this as an "existing item"; the class gets created/copied in my soultion folder everytime. And each time I edit/update the contents of that class, I have to update all the Library.Controls.FlatButton.cs files in every project folder.

I need to be able to edit a single source of FlatButton class and when I compile/build a project (that uses the class file) gets updated to the new version of that class.
Question 1: Is there a way to do this?

I know that I can gather all these classes in a library project (Library.Controls) and add it to each application solution as a dependency.
Question 2: Is this the only way to work from a single source of common library files? And if I do; will all the classes in the Library.Controls namespace get compiled with every application, even if I've only used this FlatButton class in the project?

Hope this is clear for you..
thanks

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

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

发布评论

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

评论(3

最舍不得你 2024-09-25 00:57:04

我宁愿采用共享库的方法并将它们添加为对您的客户端项目的引用。

如果你不想这样做。您可以将该文件添加为“链接”。在“添加现有项目”中,选择“添加为链接”。

I'd rather go with the approach of the shared library and add them as references to your client project.

If you don't want to do this. You could add the file as "Link". In Add existing item, select Add as Link instead.

凉城凉梦凉人心 2024-09-25 00:57:04

是的,类库是正确的选择,是的,由于整个类库将从您的应用程序中引用,因此所有类都可供它使用。

然而,所有类都可用这一事实并不是一件坏事,因为它们位于单独的类库中,它不会使您的应用程序更难理解(因为这些应用程序中的代码量将保持不变),可能只是您使用了更多的硬盘空间,但如果您真的担心,您可以将类库放在 GAC 中,以便所有应用程序都引用该库的相同副本,尽管您最好研究一下首先要确保它适合您。

Yes, a class library is the way to go and yes, since the whole class library will be referenced from your applications, all the classes will be available to it.

However, the fact that all the classes are available is not a bad thing, since they're in a separate class library it won't make your applications harder to understand (since the amount of code in those applications will stay the same), it might just be that you use up a little bit more hard drive space, though if you really worry about that you could put the class library in the GAC so that all apps reference the same copy of the library, though you'd better research this first to make sure that it's suitable for you.

过期情话 2024-09-25 00:57:04

另一种方法是添加 FlatButton.cs 文件“作为链接”:
替代文本

Alternative way is to add FlatButton.cs file "As Link":
alt text

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