简体   繁体   English

.net如何明智地使用.dll?

[英].net howto use .dlls wisely?

In my current .net projects I am using various .dlls files, some externaly written and some created by me. 在我目前的.net项目中,我使用各种.dll文件,一些是外部编写的,一些是由我创建的。 Now I am asking myself , what are the best practises to handle different .dll files over different solutions and projects and get them working with SVN so that they are available to use among different developers. 现在我问自己,在不同的解决方案和项目中处理不同.dll文件的最佳实践是什么,并让他们使用SVN,以便它们可以在不同的开发人员之间使用。

Okay, so I am asking about some general hints for: 好的,所以我问的是一些一般提示:

  • Should I bind the .dll Project into the different Solutions by source, or just directly by its release.dll? 我应该将.dll项目按源绑定到不同的解决方案,还是直接通过其release.dll绑定?

  • How can I prevent people getting the files by SVN to rebind the dll source (global assembly issues etc.) 如何防止人们通过SVN获取文件来重新绑定dll源(全局程序集问题等)

  • Is it good to use as much .dlls as possible (divide them by functionality), or using one big .dll, to get an easier overview? 使用尽可能多的.dll(按功能划分)或使用一个大的.dll来获得更简单的概述是否合适?

Please don't be too hard, I am a beginner in this business and english is not my native language. 请不要太难,我是这个行业的初学者,英语不是我的母语。

Thank you in advance, Harry. 哈利,先谢谢你。

The thing about DLLs in .NET is that they aren't at all like DLLs in pre .NET windows programming. 关于.NET中DLL的事情是它们在.NET .NET编程之前根本不像DLL。 They are just containers for code. 它们只是代码的容器。

I read a good article a couple of years ago that explained this too me, as it once confused me too - it was, I believe, written by one of the MS patterns and practices people, talking about the relationships between namespaces, assemblies, projects and solutions (if i find it I'll post the link). 几年前我读了一篇很好的文章,这也解释了我,因为它曾经让我感到困惑 - 我相信,它是由一个MS模式和实践人员编写的,讨论命名空间,程序集,项目之间的关系和解决方案(如果我发现它,我会发布链接)。

For source control purposes, I think you are better off storing the code, and letting it compile on the machine of the end users. 出于源代码控制的目的,我认为您最好存储代码,并让它在最终用户的机器上进行编译。 Putting the compiled DLLs into source control is usually something you do for 3rd party dependencies. 将已编译的DLL放入源代码控制中通常是您为第三方依赖项所做的事情。

This is all just from my experience - some experts may have better advice. 这完全取决于我的经验 - 一些专家可能会有更好的建议。

I would suggest setting up own NuGet feeds that contain your external dlls. 我建议设置包含外部dll的自己的NuGet提要。 You can setup NUGet feed just as a shared folder (no installation required). 您可以将NUGet Feed设置为共享文件夹(无需安装)。 Those feeds will be internal in your organization and you have full control over upgrades. 这些Feed将在您的组织内部,您可以完全控制升级。

Multiple projects can share the same dlls by using the same NuGet package. 多个项目可以使用相同的NuGet包共享相同的dll。

http://docs.nuget.org/docs/creating-packages/hosting-your-own-nuget-feeds http://docs.nuget.org/docs/creating-packages/hosting-your-own-nuget-feeds

I think using dll's in your application isn't a question that can be answered with yes it is good or no it is not good, since it depends on why are which dll's you are using. 我认为在你的应用程序中使用dll不是一个可以回答的问题,是好的或不好的,因为它取决于你为什么使用哪个dll。

So if you are using 3rd parties dll's in your solution already I think putting your code instead of the dll's you are creating will be the best practice here so that you don't have many dll's and your compiler won't have references for many dll's as well. 因此,如果您在解决方案中使用第三方dll,我认为放置代码而不是您正在创建的dll将是最好的做法,这样您就没有很多dll,并且您的编译器将不会有许多dll的引用同样。

I think 3 layers architecture is good practice. 我认为3层架构是很好的做法。

GUI.dll GUI.dll
Business.dll Business.dll
DataAccess.dll DataAccess.dll

I prefer project references instead of DLL references, because you reference the Debug dll in debug configuration and the Release dll in Release configuration. 我更喜欢项目引用而不是DLL引用,因为您在调试配置中引用Debug dll并在Release配置中引用Release dll。

Generally you should divide your code into different assemblies if there are a good reason to do it like.... 一般来说,如果有充分的理由,你应该将你的代码划分为不同的程序集....

  • You are using the code of the assembly in different projects 您正在使用不同项目中的程序集代码
  • You want to seperate your data from the GUI 您想要从GUI分离数据
  • The DLL is updated many times and to keep it simple you want to update just a small part of it DLL会多次更新,为了简单起见,您只想更新它的一小部分

There are many reasons to put code into dll's instead putting it in one big project. 有很多理由将代码放入dll中,而不是把它放在一个大项目中。 But you should not create to many dll's if there are no reason to do it ( I've seen some ppl creating one dll for each namespace and they contained not so many classes and there have been no reason to split them ). 但是如果没有理由这么做就不应该创建许多dll(我已经看到一些ppl为每个命名空间创建一个dll,它们包含的类不是很多,并且没有理由将它们拆分)。

Of course splitting code into dll's can cause some problems like you have a class in dll a and a class in dll b and each of them need a reference to another. 当然,将代码拆分成dll可能会导致一些问题,比如你在dll a中有一个类,在dll b中有一个类,并且每个都需要引用另一个。 This is mostly a design issue of the application. 这主要是应用程序的设计问题。

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

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